ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
The code in use is shown below.
The following code works fine but it also populates my listbox if the value consists of N/A
I start to search for N & there all listed.
How would i have the code to NOT populate the listbox & to ignore it if its value is N/A thus just populating it with any other N value
The following code works fine but it also populates my listbox if the value consists of N/A
I start to search for N & there all listed.
How would i have the code to NOT populate the listbox & to ignore it if its value is N/A thus just populating it with any other N value
Rich (BB code):
Private Sub TextBoxKeyCode_Change()
Me.Label1.Visible = False
Me.Label2.Visible = False
Me.Label3.Visible = False
Me.Label4.Visible = False
TextBoxKeyCode = UCase(TextBoxKeyCode)
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 = 4
.ColumnWidths = "190;180;230;10"
If TextBoxKeyCode.Value = "" Then Exit Sub
Set r = Range("J5", Range("J" & Rows.Count).End(xlUp))
Set f = r.Find(TextBoxKeyCode.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(, -8).Value
.List(i, 2) = f.Offset(, -9).Value
.List(i, 3) = f.Row
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Offset(, -8).Value
.List(.ListCount - 1, 2) = f.Offset(, -9).Value
.List(.ListCount - 1, 3) = f.Row
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> cell
TextBoxSearch = UCase(TextBoxSearch)
.TopIndex = 0
Else
MsgBox "NO SUCH KEY CODE", vbCritical, "DATABASE SHEET ITEM SEARCH"
TextBoxKeyCode.Value = ""
TextBoxKeyCode.SetFocus
End If
End With
End Sub