ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,884
- Office Version
- 2007
- Platform
- Windows
On a command button i have the following code.
It sorts my sheet column D from A-Z
Once done my userform opens
I press a command button to now load the values from the sheet that has just been sorted column D A-but Listbox isnt the same order.
This is the code.
Here is a screen shot of my partial sheet & then Listbox
Im expecting the Listbox to look the same as the sheet
The first value is correct AFRICA TWIN but then it starts in reverse being XL700 when it should be starting at CB1000
Please advise what went wrong thanks.
It sorts my sheet column D from A-Z
Once done my userform opens
I press a command button to now load the values from the sheet that has just been sorted column D A-but Listbox isnt the same order.
This is the code.
Rich (BB code):
Private Sub CheckConnectorsUsed_Click()
Dim r As Range, f As Range, Cell As String, added As Boolean
Dim sh As Worksheet
Dim i As Long
Set sh = Sheets("MCLIST")
sh.Select
With ListBox1
.Clear
.ColumnCount = 4
.ColumnWidths = "100;170;70;10"
Set r = Range("C8", Range("C" & Rows.Count).End(xlUp))
Set f = r.Find(TextBox1.Value, LookIn:=xlValues, LookAt:=xlPart)
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(, 1).Value ' MODEL
.List(i, 2) = f.Offset(, 6).Value ' YEAR
.List(i, 3) = f.Offset(, 9).Value ' CONNECTOR USED
.List(i, 4) = f.Row
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Offset(, 1).Value ' MODEL
.List(.ListCount - 1, 2) = f.Offset(, 6).Value ' YEAR
.List(.ListCount - 1, 3) = f.Offset(, 9).Value ' CONNECTOR USED
.List(.ListCount - 1, 4) = f.Row
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
Here is a screen shot of my partial sheet & then Listbox
Im expecting the Listbox to look the same as the sheet
The first value is correct AFRICA TWIN but then it starts in reverse being XL700 when it should be starting at CB1000
Please advise what went wrong thanks.