Macro Filter Selected Cell value

Exn

New Member
Joined
Jan 27, 2011
Messages
6
Hello!

I'm new to this forum & not so great at coding Excel Macros!:confused:

I'm trying to creat a macro that performs the function Filter by selected Cells Value.

I use the record macro function & ive tried doing this by changing relative references, but i get the same result.

This is my code:

ActiveCell.Offset(3, 0).Range("A1").Select
ActiveSheet.Range("$G$4:$G$12").AutoFilter Field:=1, Criteria1:="4"

I want it so that the filtering criteria depends on which Box I am highlighting at the time. The code writes this as the example that i used when recording it. ( 4 )

Any ideas how to solve this?

Thanks in advance
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Welcome to the board.

Maybe this:
ActiveSheet.Range("$G$4:$G$12").AutoFilter Field:=1, Criteria1:=ActiveCell.Value
 
Upvote 0
Thanks Just what I was looking for. I knew it would be something straight forward.
 
Upvote 0
In addition, this code just sets it to the specific column I was in. Can this be done on any coumn that I am in? I've been playing around with Active Column but can't quite get it to work...
 
Upvote 0
For my original coding it just sets it to the one column i made a test dummy for.( G:G in my coding)

Essentially, what I am trying to do, is to create a macro that replicates "the filter by cell value" function (Basically so I can create a shortcut key to it as I use it so often).

When recording the macro, vba just sets it to the column & value that I recorded it with. So when I try to filter a different column & value it still filters on the original values.

You solved the first problem of the values(Thank you!!), but how would this be coded to filter a set of data with numerous coulmns, so I can use this in other columns and other reports with different amounts of columns?
 
Upvote 0
Code:
Sub Autofilter_by_selection()

Range(ActiveCell.CurrentRegion.Address).AutoFilter Field:=ActiveCell.Column, Criteria1:=ActiveCell.Value
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,656
Members
449,091
Latest member
peppernaut

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