ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Morning,
I have a userform which when i select CheckBox1 i would like the code to search column G on my worksheet for the word YES then populate my ListBox with the required info.
I have the code below for which im using & follows my other codes on this form but im confused on how to set the word YES as the CheckBox1 value so the code knows what to search for when the user selecyts the CheckBox.
Thanks
I have a userform which when i select CheckBox1 i would like the code to search column G on my worksheet for the word YES then populate my ListBox with the required info.
I have the code below for which im using & follows my other codes on this form but im confused on how to set the word YES as the CheckBox1 value so the code knows what to search for when the user selecyts the CheckBox.
Thanks
Rich (BB code):
Private Sub CheckBox1_Click()
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 = 3
.ColumnWidths = "100;100;100"
If CheckBox1.Value = "" Then Exit Sub
Set r = Range("G3", Range("G" & Rows.Count).End(xlUp))
Set f = r.Find(CheckBox1.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.Row
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Row
.List(i, 1) = f.Offset(, 1).Value
.List(i, 2) = f.Offset(, 2).Value
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Offset(, 1).Value
.List(.ListCount - 1, 2) = f.Offset(, 2).Value
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> cell
.TopIndex = 0
Else
MsgBox "NO CUSTOMER WAS FOUND", vbCritical, "CLONING INFORMATION MESSAGE"
CheckBox1.Value = ""
End If
End With
End Sub
Last edited: