wild card to listbox

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I am using the following code to populate a listbox on a userform. But now I want to apply it to another listbox, however the column actually has text such as "fire extinguisher 01, Fire extinguisher 02, fire hose 13...." How can I tweak this code to add a wild card so that my query will include any instance of the text "fire" to be included in to the listbox. so that I can get them all regardless of the number. Thank you for the help.


VBA Code:
Private Sub FireExtinguisherLabel_Click()

     Dim i As Long
    Dim Lastrow As Long
      
    ListBox1.SetFocus
    
 'this is from the DEVICE ID column
    Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
         For i = 1 To Lastrow
             If Cells(i, 8).Value = "" And Cells(i, 2).Value = "Fire" Then ListBox1.AddItem Cells(i, 3).Value & " - " + Cells(i, 4).Value
         Next
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You'd need to use Like operator in your query, not alter that code, I would think.
 
Upvote 0
Solution
yes, all I had to do was swap the "=" for the "Like" operator, that was easier than I thought - thanks,
 
Upvote 0

Forum statistics

Threads
1,215,262
Messages
6,123,953
Members
449,135
Latest member
jcschafer209

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