VBA code to filter a column from a cell reference in a different worksheet

dlamle

New Member
Joined
Jul 2, 2015
Messages
38
I am wanting to create a filter for just Column AG in a worksheet titled "Darren" based off cell C8 in a worksheet titled "Control Sheet". The cell I want to reference is a value.

Below is the VBA code that I am currently using but every time I run the Macro is returns a message saying "Compile Error: Syntax Error" . Hopefully someone can help me out!

Sub Darren()
'


' Darren Macro
'


'
ActiveSheet.Range("$AG$2:$AG$2000").Autofilter Field:=33, Criteria1:=Worksheets("Control Sheet").Range("C8").Value.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Sub Filter_Sheet ()
ActiveSheet.Range("$A$1:$O$2093").AutoFilter Field:=1, Criteria1:="=" & Worksheets("Sheet1").Range("A3").Value
End Sub


This should work, let me know!
 
Upvote 0
Sub Filter_Sheet ()
ActiveSheet.Range("$A$1:$O$2093").AutoFilter Field:=1, Criteria1:="=" & Worksheets("Sheet1").Range("A3").Value
End Sub


This should work, let me know!

It worked great, thank you!

I noticed that I have to have the "Forecast" tab selected for the macro to work. Is there a way to have a button on "sheet1" that will run the macro without having to select the "forecast" tab?

*update* In regard to my last question, I figured it out. Thanks again for your help!
 
Last edited:
Upvote 0
Yes!
-Click the developer tab
-Click Insert, and select the button (form controls)
-Create a box and assign the macro you created!

Everytime you click the button the macro will run
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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