ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Morning,
I am using the following code & have also supplied screen shot of userform.
When the listbox is populated i see customers name top to bottom in the sort of Z to A
My goal is to sort top to bottom A to Z
Please advise what i need to do.
Thanks
I am using the following code & have also supplied screen shot of userform.
When the listbox is populated i see customers name top to bottom in the sort of Z to A
My goal is to sort top to bottom A to Z
Please advise what i need to do.
Thanks
Rich (BB code):
Private Sub SearchForm_Click()
Dim R As Range, f As Range, cell As String, added As Boolean
Dim sh As Worksheet
Set sh = Sheets("DATABASE")
sh.Select
With ListBox1
.Clear
.ColumnCount = 5
.ColumnWidths = "150;210;190;190;50"
If ComboBox1.Value = "" Then Exit Sub
Set R = Range("I6", Range("I" & Rows.Count).End(xlUp))
Set f = R.Find(ComboBox1.Value, LookIn:=xlValues, LookAt:=xlWhole)
If Not f Is Nothing Then
cell = f.Address
Do
added = False
For i = 0 To .ListCount - 1
Select Case StrComp(.List(i), f.Value, vbTextCompare)
Case 0, 1
.AddItem f.Value, i
.List(i, 1) = f.Offset(, -8).Text
.List(i, 2) = f.Offset(, -5).Value
.List(i, 3) = f.Offset(, -3).Value
.List(i, 4) = f.Offset(, -2).Value
.List(i, 5) = f.Offset(, -1).Value
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Offset(, -8).Text
.List(.ListCount - 1, 2) = f.Offset(, -5).Value
.List(.ListCount - 1, 3) = f.Offset(, -3).Value
.List(.ListCount - 1, 4) = f.Offset(, -2).Value
.List(.ListCount - 1, 5) = f.Offset(, -1).Value
End If
Set f = R.FindNext(f)
Loop While Not f Is Nothing And f.Address <> cell
.TopIndex = 0
Else
End If
End With
End Sub