Table Criteria based on cell value?

gino59

Active Member
Joined
Jul 26, 2010
Messages
496
Hi all,

I'm trying to figure out how to specify an Excel 2010 table filter by reading the value in a cell located on a different worksheet.

I have the table on sheet "mData1". I'd like to filter that table based on the cell value on sheet "MBR" in cell R4.

Here's a snippet of the code...

Code:
    Sheets("mdata1").Activate
    ActiveSheet.ListObjects("mData").Range.AutoFilter Field:=3, Criteria1:= _
        Sheets("MBR") & Range("R4").Text


How can I specify the criteria to read the value in cell R4 on the MBR worksheet and then filter the table on the mData sheet?

Many many thanks in advance!!

Cheers,
Gino
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Untested:

What if you use
Code:
, Criteria1:= Sheets("MBR").Range("R4").Text
for the criteria?
Does that work?
 
Upvote 0
Thanks for the reply, Joe4 - yes, that worked!!

Someday, maybe I might just figure out syntax! I actually tried to get creative and decided I need more than just the month filter and added a year filter. Concatenated both fields into R5 and defined a name for that cell (MOsel). I changed the code to:

Code:
     Sheets("mData1").Activate
     ActiveSheet.ListObjects("mData").Range.AutoFilter Field:=1, Operator:= _
          xlFilterValues, Criteria2:=Array(1, MOsel)

and now I can filter via two criteria (month & year).




;)

Many thanks again!!

Cheers,
Gino
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

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