Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Just in case, here's a small list from that page:

vbBack - A backspace character [Chr(8)]


vbCr - A carriage return [Chr(13)]
vbCrLf - A carriage return and line feed [Chr(13) + Chr(10)]
vbLf - A linefeed [Chr(10)]
vbNewLine - A platform-specific new line character
vbNullChar - A null character of value 0 [Chr(0)]
vbNullString - A string of value 0 [no Chr code]
vbTab - A tab character [Chr(9)]

Also check online for an ASCII table, so you can use the CHR function (for example,
using chr(32) for space, etc - you can even use these character codes for action
keys like escape (chr 27) and so on). Just in case again, here's a link:

--------------LISTBOX----------

Single Selection ListBox

As mentioned above, we can have our user select one, or more items in a ListBox.
The procedure below take a single selected ListBox item and places it into a range
at the bottom of a list.

Sheet2.Range("A65536").End(xlUp)(2, 1) = ListBox1.Value
For such code to work the ListBox must have its MultiSelect Property set to 1
fmMultiSelectSingle

MutliSelect Property is -1 fmMultiSelectMulti

When have set the MultiSelect Property set to -1 fmMultiSelectMulti we can allow
users to make multiple selections. However, due to MultiSelect Property set to -1
fmMultiSelectMulti we can no longer use simple code like above to return the
selected items to our cells. To do this with multiple selections we can use code
like shown below;

Private Sub CommandButton2_Click()

Dim lItem As Long

For lItem = 0 To ListBox1.ListCount - 1

If ListBox1.Selected(lItem) = True Then

Sheet2.Range("A65536").End(xlUp)(2, 1) = ListBox1.List(lItem)

ListBox1.Selected(lItem) = False

End If

Next

End Sub

-----------------------------------------------------
Dim iIndex
Dim iInd2
With lboMICHNAME
iIndex = lboMICHNAME.ListIndex
lboMICHsummary.AddItem .List(iIndex, 0), 0
iInd2 = lboMICHsummary.ListCount - 1
For x = 1 To lboMICHNAME.ColumnCount - 1
lboMICHsummary.List(iInd2, x) = .List(iIndex, x)
Next x
End With

----------------

Sub SortAndRemoveDupes()

Dim rListSort As Range, rOldList As Range

Dim strRowSource As String

'Clear Hidden sheet Column A ready for list

Sheet1.Range("A1", Sheet1.Range("A65536").End(xlUp)).Clear

'Set range variable to list we want

Set rOldList = Sheet2.Range("A1", Sheet2.Range("A65536").End(xlUp))

'Use AdvancedFilter to copy the list to Column A _

of the hidden sheet and remove all dupes

rOldList.AdvancedFilter Action:=xlFilterCopy, _

CopyToRange:=Sheet1.Cells(1, 1), Unique:=True


'Set range variable to the new non dupe list

Set rListSort = Sheet1.Range("A1", Sheet1.Range("A65536").End(xlUp))

'Sort the new non dupe list

With rListSort

.Sort Key1:=.Cells(2, 1), Order1:=xlAscending, Header:=xlYes, _

OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

End With

'Parse the address of the sorted unique items

strRowSource = Sheet1.Name & "!" & Sheet1.Range _

("A2", Sheet1.Range("A65536").End(xlUp)).Address

Sheet1.Range("A1") = "New Sorted Unique List"

With UserForm1.ListBox1

'Clear old ListBox RowSource

.RowSource = vbNullString

'Parse new one

.RowSource = strRowSource

End With

You might also like