Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

auto filtering using results

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Auto Filtering using results from toggle button

Auto Filtering using results from toggle button

ResolvedVersion 2010

Adam has attended:
Excel VBA Intro Intermediate course

Auto Filtering using results from toggle button

Hi Guys,

I am trying to design a user form that i can use to auto filter data on a sheet in my workbook.

Basically i have 36 toggle buttons which can be on or off and i want the values if true to be passed on to an autofilter criteria.

Any suggestions on the best way to achieve this?

Thanks
Adam

RE: Auto Filtering using results from toggle button

Hi Adam

Thanks for getting in touch.

You can take the value of the toggle (option button, check box etc) and embed it in a SELECT CASE structure.

Have a look at this example, where an option button control changes whether to show January's or February's data:

SELECT CASE optionbutton1.value

CASE TRUE
ActiveSheet.Range("$A$1:$X$69").AutoFilter Field:=3, Criteria1:= _
"January"

CASE FALSE
ActiveSheet.Range("$A$1:$X$69").AutoFilter Field:=3, Criteria1:= _
"February"

END SELECT

And you could modify the range to something more dynamic, change the field number to the relevant field and change the criteria to a variable if appropriate.

I hope this helps, let us know how you get on.

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Auto Filtering using results from toggle button

Hi Gary,

Thanks for getting back in touch. in the end I managed to use code that wrote a value into a cell for each toggle button.

If toggleGun1.Value = True Then
toggleGun1.BackColor = RGB(255, 0, 0)
Sheets("Sheet1").Range("A1") = 1

Else
toggleGun1.BackColor = RGB(0, 255, 0)
Sheets("Sheet1").Range("A1") = ""
End If

Your way looks a bit silkier though!

Cheers
Adam

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Toggle Formulas and Results

Ctrl + 'The key above Tab with the

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.