Macro that filters a table based on a single Cell's value.

Kelko

New Member
Joined
Nov 17, 2015
Messages
4
Is there a way to use a macro that when run will filter a data table based on a fill in the balk cell value? By fill in the blank I mean to reference a cell that's outside of the table, that when a user types in a number, say "R250", that the macro knows to use the input "R250" to filter a filed in my data table? I'm essentially trying to make a simple filed search query with for a single value input. It seems I can't reference when using the filter option under a filed heading, or get a macro to copy and paste a cell's value into the filter function.
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try this:
Code:
Sub Filter_Me()
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:=[COLOR="#FF0000"]Cells(1, 10).Value[/COLOR]
End Sub
 
Upvote 0
Try this:
Code:
Sub Filter_Me()
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:=[COLOR=#ff0000]Cells(1, 10).Value[/COLOR]
End Sub

Thank you for your help.

Is this what the code should look like after inserting my data? I'm a little unsure (a lot rather) about the end the first line
" Criteria=" area.

Code:
Sub SearchMeNow()
Sub Filter_Me()
ActiveSheet.ListObjects("RingGages").Range.AutoFilter Field:=6, Criteria1:=Cells(P, 20).Value
End Sub
'
' SearchMeNow Macro.


The table I'm trying to filter is called "RingGages", and I'm trying to filter filed 6 which contains each gage's individual identification number. I'd like the cell "P20" to be used as a search box so that when a user types in a gage number in "P20", the macro uses the info in cell "P20" to filter the table.

Hope you can help. Thank you again.
 
Upvote 0
You cannot use:
Criteria1:=Cells(P, 20).Value


You must use:
Criteria1:=Cells(16, 20).Value

You must use numbers not characters.

And why two subs?
Sub SearchMeNow()
Sub Filter_Me()
 
Upvote 0
Did you create this table and it came out named like this:
ActiveSheet.ListObjects("RingGages").Range.AutoFilter Field:=6, Criteria1:=Cells(P, 20).Value

Most Tables are named Table1 or Table2
If you name your Table "RingeGages" then I think it must look like this:

ActiveSheet.Range("RingeGages").AutoFilter Field:=6 ', Criteria1:=Cells(16, 20).Value
 
Upvote 0
Did you create this table and it came out named like this:
ActiveSheet.ListObjects("RingGages").Range.AutoFilter Field:=6, Criteria1:=Cells(P, 20).Value

Most Tables are named Table1 or Table2
If you name your Table "RingeGages" then I think it must look like this:

ActiveSheet.Range("RingeGages").AutoFilter Field:=6 ', Criteria1:=Cells(16, 20).Value

You are correct, I did name the table " RingGages". What do the 16 and 20 represent? I'm not sure how they work into the code? Total novice here.

As for the two Sub's, I just made a mistake when copying the code back into this thread.
 
Upvote 0
16 equals Column 16
20 equals row 20
I should have wrote it this way
Cells(20, 16).Value
 
Upvote 0
Then your script should look like:
ActiveSheet.ListObjects("Table4").Range.....
 
Upvote 0

Forum statistics

Threads
1,216,089
Messages
6,128,750
Members
449,466
Latest member
Peter Juhnke

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