Using auto Filter with Macro

mbg1261

New Member
Joined
Jan 10, 2005
Messages
4
I'm new to working with macros, and was wondering if it's possible when using a Macro to Auto Filter to use first use a message box to pick the critieria. For Example can I have a message pop up to ask which payroll period do you want? and then the user selects say 1, 2, 3, or 4 and then have the macro sort on whatever the user has entered? Any help would be appreciated!
 
Welcome to the Board!

How about something along these lines:

<font face=Tahoma><SPAN style="color:#00007F">Sub</SPAN> CustomFilter()
    <SPAN style="color:#00007F">Dim</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
        x = Application.InputBox("Please enter a Pay Period Number", "Pay Period", Type:=1)
        
        Worksheets("Sheet1").Range("A1").AutoFilter Field:=1, Criteria1:=x

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,

Smitty
 
Upvote 0
Hi mbg1261:

Welcome to MrExcel Board!

I am sorry, I don't get it ...

Let us see ... if your PayPeriods 1 through 4 are in corresponfing columns 1 through 4 with your data starting in column A.

then I think in Smitty's macro, after you get the PayPeriod prompted, then if you use Field:=x, Filtering will be done on the corresponding PayPeriod, but I still don't get what criteria is to be used in executing the Filter.
 
Upvote 0
Upvote 0

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