I use this code to search in the list box and it works well, but when I search in the first column in the list box for a number, for example 1, 2 or 3, it gives me all the numbers that contain these numbers, so how can I make it show me in the list box only the specified number in the search
VBA Code:
Dim x, ws As Worksheet, i As Long, j As Long, lastrow As Long
With salles_safty.ListBox1
.Clear
.ColumnCount = 15
.ColumnWidths = "55 pt;63 pt;55 pt;150 pt;63 pt;120 pt;55 pt;55 pt;55 pt;55 pt;55 pt;55 pt;55 pt;55 pt;55 pt"
Set ws = ThisWorkbook.Sheets("ledger")
x = Application.Match(salles_safty.ComboBox2.Value, ws.Rows(2), 0)
If Not IsError(x) Then
lastrow = ws.Cells(Rows.Count, "G").End(xlUp).Row
Dim a, myCols, ii As Long
ReDim a(1 To 15, 1 To lastrow)
myCols = Array(26, 8, 5, 7, 132, 20, 208, 46, 47, 48, 51, 52, 53, 49, 50)
For i = 3 To lastrow
If salles_safty.TextBox4 <> "" And InStr(ws.Cells(i, x), salles_safty.TextBox4) <> 0 Then
j = j + 1
For ii = 0 To UBound(myCols)
a(ii + 1, j) = ws.Cells(i, myCols(ii)).Value
Next
End If
Next i
'1111111111111111111111
For i = 3 To lastrow
If salles_safty.TextBox4 = "" Then
j = j + 1
For ii = 0 To UBound(myCols)
a(ii + 1, j) = ws.Cells(i, myCols(ii)).Value
Next
' salles_safty.t8.Value = Val(salles_safty.t54) / Val(salles_safty.t7)
' salles_safty.t8.Text = Format(salles_safty.t8.Text, "0.00")
'salles_safty.ListBox1.List(i, 16) = Val(salles_safty.ListBox1.List(i, 12)) + Val(salles_safty.ListBox1.List(i, 14)) '+ Val(salles_safty.ListBox1.List(i, 15))
End If
Next i
'1111111111111111111111
ReDim Preserve a(1 To UBound(a, 1), 1 To j)
.Column = a
End If
End With