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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
If you want to filter col Ag and your range is in AG then the field is 1.
Try:
Rich (BB code):
Range("$AG$2:$AG$2000").AutoFilter Field:=1, Criteria1:=Worksheets("Control Sheet").Range("C8").Value
 
Upvote 0
Great catch!

I made the adjustment but am still getting the same error message
The line I posted produces no syntax error - did you try copying it directly from your browser and pasting it to the VBE window?
 
Upvote 0
I did and yes it fixed the issue, thank you!

Now the next step, I want show numbers greater than or equal to C8.

Currently I have this code

Range(">=C8").Value
 
Upvote 0
I did and yes it fixed the issue, thank you!

Now the next step, I want show numbers greater than or equal to C8.

Currently I have this code

Range(">=C8").Value
You are welcome.

Range(">=C8") is not a valid range object. Try
Code:
Range("$AG$2:$AG$2000").AutoFilter Field:=1, Criteria1:=">=" & Worksheets("Control Sheet").Range("C8").Value
 
Upvote 0
Hi i'm new to VBA and i'm trying to auto filter data on a sheet titled "Forecasts" by referencing cell A3 on a sheet titled "Sheet1".I'm unsure how to code this from start to finish. Any help anyone could give would be much appreciated! Thanks!
 
Upvote 0
What is the range of your data in the "Forecasts" tab?? And what column are you wanting to filter on it?
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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