Assign Macro to Checkbox in order to set criteria on Autofilter

Djro69

New Member
Joined
Nov 2, 2020
Messages
15
Office Version
  1. 2019
Platform
  1. Windows
Hi all - hope you're having a nice day.

Q) Can I create 3 lazy checkboxes 1, 2 & 3 to filter for XXX only, YYY only, ZZZ only respectively?

I added the checkboxes via Developer > Insert > Checkbox (form control) <<<< but perhaps there is a better option?

AssignMacroToCheckbox.PNG
 

Attachments

  • AssignMacroToCheckbox.PNG
    AssignMacroToCheckbox.PNG
    21.2 KB · Views: 1

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi DJro,

You can use a slicer.

  1. Select your data from A7 to D22
  2. Press Ctrl & T
  3. Tick the option 'Contains headers' - This will format your data as a table.
  4. Click on 'Table design' in the ribbon - (green below)
  5. Click on 'Insert slicer'
  6. Select the option for 'Place'
It will now add in a control like the below that will do what you need.


1723811062931.png
 
Upvote 0
Thanks sxhall, it's a good suggestion for other circumstances but I need to keep it as is and not in a table or pivot or anything.

So really need some vba if someone has it?
 
Upvote 0
You will need to use option buttons instead then as only one can be selectd at any given time. Bound them in a 'Groupbox' as well if you need to.

Code will be as follows for the buttons...

VBA Code:
Sub MacroXXX()

    ActiveSheet.Range("$A$8:$D$22").AutoFilter Field:=2, Criteria1:="xxx"
   
End Sub

Sub MacroYYY()

    ActiveSheet.Range("$A$8:$D$22").AutoFilter Field:=2, Criteria1:="yyy"
   
End Sub

Sub MacroZZZ()

    ActiveSheet.Range("$A$8:$D$22").AutoFilter Field:=2, Criteria1:="yyy"
   
End Sub

1723818231657.png
 
Upvote 0
Solution
Thank you - I did not know about option buttons! These are perfect for what I'm working on!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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