VBA Filter by checkboxes

alfordtp

Board Regular
Joined
Oct 3, 2008
Messages
62
I have a userform with checkboxes. Based on those checkboxes, I want my data to filter to show what is checked as the criteria.

AppleRedLargeNew
AppleGreenSmallNew
AppleRedSmallOld
BananaYellowLargeNew
BananaGreenSmallNew

<tbody>
</tbody>


For example, if Green,Small, and New were checked, it would give me the second apple and the second banana records. Each column has a set of check boxes. As in the example, not all columns must have a selection to filter the data.

What is the best way to check all the check box values and filter based on that? I understand that an advanced filter would work, but I dont want to create lots of "if" statements to filter. Is there a way to keep filtering the data as the code is cycling through the check boxes?
 

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)
My first thought is that you'll have a lot of checkboxes... (9 in your example).

I would create one macro that does the filtering. All the check boxes would trigger the same macro. At the beginning of the macro, there would be some sort of "for each checkbox in sheets().checkboxes" and that would build a string of what to filter for.

You could either use a select case to decide which fields to filter, based on what's checked; or, you could make a 'helper column' that concatenates all relevant fields and only requires one 'filtered column.'

More of a brainstorm than a definitive solution, but maybe it'll give you some ideas.
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,722
Members
449,465
Latest member
TAKLAM

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