ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Morning,
I am using the code below
My worksheet has values in columns ABCD
When the listbox on my userform is populated i only see values from columns ABC
Can you see what ive done wrong so column D isnt being shown
I am using the code below
My worksheet has values in columns ABCD
When the listbox on my userform is populated i only see values from columns ABC
Can you see what ive done wrong so column D isnt being shown
Rich (BB code):
Private Sub TextBox1_Change()
TextBox1 = UCase(TextBox1)
Dim r As Range, f As Range, cell As String, added As Boolean
Dim sh As Worksheet
Set sh = Sheets("KEYCODES")
sh.Select
With ListBox1
.Clear
.ColumnCount = 4
.ColumnWidths = "250;100;120;120"
If TextBox1.Value = "" Then Exit Sub
Set r = Range("A3", Range("A" & 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
.List(i, 2) = f.Offset(, 2).Value
.List(i, 3) = f.Offset(, 3).Value
.List(i, 4) = f.Offset(, 4).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
.List(.ListCount - 1, 3) = f.Offset(, 3).Value
.List(.ListCount - 1, 4) = f.Offset(, 4).Value
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> cell
TextBox1Search = UCase(TextBox1Search)
.TopIndex = 0
Else
MsgBox "NO INFO WAS FOUND", vbCritical, "KEY CODE SEARCH MESSAGE"
TextBox1.Value = ""
TextBox1.SetFocus
End If
End With
End Sub