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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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