VBA Search Box, Sort Multiple Table Column and Begins With/Contains Option

partsbbw

New Member
Joined
Jan 18, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I am trying to create a code to search multiple table columns and also have a begins with and contains option. I created seperate option button groups for the table columns and another for begins with and contains option buttons. My problem is that I'm not sure how to get the begins with and contains option to filter to the different columns. Right now, no matter what column option I select, it will only filter my second column "Brand". The begins with/ contain options work well otherwise. I need to know how to apply begins with/contains options to columns/fields 2-4 and not just one.
Thank you for any help or suggestions.
Screenshot 2022-02-24 230316.png



Screenshot 2022-02-24 230206.png


VBA Code:
Private Sub txtSearchBox_Change()

If optBrand Then
    ListObjects("SDS.Table").Range.AutoFilter Field:=2, Criteria1:="*" & Range("F2") & "*"
End If

If optName Then
    ListObjects("SDS.Table").Range.AutoFilter Field:=3, Criteria1:=Range("F2") & "*"
End If

If optRefNo Then
    ListObjects("SDS.Table").Range.AutoFilter Field:=4, Criteria1:=Range("F2") & "*"
End If

If optBeginsWith Then
    ListObjects("SDS.Table").Range.AutoFilter Field:=2, Criteria1:=Range("F2") & "*"
Else
    ListObjects("SDS.Table").Range.AutoFilter Field:=2, Criteria1:="*" & Range("F2") & "*"
End If

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,093
Latest member
catterz66

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