Autofilter TextBox with Multiple ActiveX Option Buttons

sdennant

New Member
Joined
Mar 17, 2020
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I can't seem to wrap my head around this... Basically i have create a worksheet with a textbox whereby when i search for a word it autofilters a selected column. I also have three option buttons that in theory, i would want a user to select whichever button and that would dictate where that textbox searches. I only have one text box and three different buttons.

What i found that happens is, if a user selects one button and types, it filters correctly, then if you select another one it keeps the first filter and applies a second. but i actually want it only to filter one at a time if that makes sense?

I've also attached a screenshot of the search bar textbox i have created.

Here's the code:

VBA Code:
Private Sub NameTextBox_DropButtonClick()

If ActiveSheet.OptionButton1 = True Then
    ActiveSheet.ListObjects("Names").Range _
    .AutoFilter Field:=19, Criteria1:="=*" & NameTextBox.Text & "*"
    Else
        End If

If ActiveSheet.OptionButton2 = True Then
    ActiveSheet.ListObjects("Names").Range _
    .AutoFilter Field:=17, Criteria1:="=*" & NameTextBox.Text & "*"
    Else
        End If
If ActiveSheet.OptionButton3 = True Then
    ActiveSheet.ListObjects("Names").Range _
    .AutoFilter Field:=18, Criteria1:="=*" & NameTextBox.Text & "*"
    Else
        End If
    
End Sub
 

Attachments

  • Capture excel.PNG
    Capture excel.PNG
    4.1 KB · Views: 7

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,213,553
Messages
6,114,279
Members
448,562
Latest member
Flashbond

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