VBA search in listbox when used combobox and textbox

saftawy1

Board Regular
Joined
Oct 12, 2021
Messages
65
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
i have this code to serch with combobox and textbox and its good in work for some column i want change it to become search appear all column in range ( a : o )

Dim x, ws As Worksheet, i As Long, j As Long, lastRow As Long
With Me.ListBox1
.Clear
.ColumnCount = 7
.ColumnWidths = "60 pt;150 pt;80 pt;150 pt;100 pt;70 pt;100 pt"
.ColumnHeads = 0
Set ws = Sheets("Ledger")
x = Application.Match(ComboBox1.Value, ws.Rows(1), 0)
If Not IsError(x) Then
lastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row
For i = 1 To lastRow
If TextBox1 <> "" And InStr(ws.Cells(i, x), TextBox1) <> 0 Then
.AddItem
.List(j, 0) = ws.Cells(i, 1)
.List(j, 1) = ws.Cells(i, 3)
.List(j, 2) = ws.Cells(i, 4)
.List(j, 3) = ws.Cells(i, 16)
.List(j, 4) = ws.Cells(i, 17)
.List(j, 5) = ws.Cells(i, 18)
.List(j, 6) = ws.Cells(i, 10)
j = j + 1
End If
Next i
End If
End With

many thanks
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top