ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Afternoon.
The following code does what i require in the way of what it should be doing BUT i would like to have the results sorted A-Z before populating the Listbox.
Currently when i tick the CheckBox the ListBox is populate like so,
ALEX
SHAUN
PETE
COLIN
Etc etc BUT i would like it to be like so,
ALEX
COLIN
PETE
SHAUN
The code below searches column G for the word YES
If you need to know the customers names are in column A
The range in use is A-M
I mention the above as i think but cant find the code that we sort A-Z in an used column THEN add to Listbox ?
The following code does what i require in the way of what it should be doing BUT i would like to have the results sorted A-Z before populating the Listbox.
Currently when i tick the CheckBox the ListBox is populate like so,
ALEX
SHAUN
PETE
COLIN
Etc etc BUT i would like it to be like so,
ALEX
COLIN
PETE
SHAUN
The code below searches column G for the word YES
If you need to know the customers names are in column A
The range in use is A-M
I mention the above as i think but cant find the code that we sort A-Z in an used column THEN add to Listbox ?
Rich (BB code):
Private Sub CheckBox1_Change()
If CheckBox1.Value = True Then
Dim r As Range, f As Range, cell As String, added As Boolean
Dim sh As Worksheet
Set sh = Sheets("DETAILS")
sh.Select
With ListBox1
.Clear
.ColumnCount = 7
.ColumnWidths = "0;180;150;150;100;80;60"
If CheckBox1.Value = "" Then Exit Sub
Set r = Range("G3", Range("G" & Rows.Count).End(xlUp))
Set f = r.Find("YES", 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(, -6).Value
.List(i, 2) = f.Offset(, -5).Value
.List(i, 3) = f.Offset(, -4).Value
.List(i, 4) = f.Offset(, -3).Value
.List(i, 5) = f.Offset(, 0).Value
.List(i, 6) = f.Offset(, 1).Value
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Offset(, -6).Value
.List(.ListCount - 1, 2) = f.Offset(, -5).Value
.List(.ListCount - 1, 3) = f.Offset(, -4).Value
.List(.ListCount - 1, 4) = f.Offset(, -3).Value
.List(.ListCount - 1, 5) = f.Offset(, 0).Value
.List(.ListCount - 1, 6) = f.Offset(, 1).Value
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> cell
.TopIndex = 0
Else
MsgBox "NO SNIFF DATA WAS FOUND", vbCritical, "CLONING INFORMATION MESSAGE"
CheckBox1.Value = ""
End If
End With
End If
If CheckBox1.Value = False Then
With ListBox1
.Clear
End With
End If
End Sub