Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 60
Default AutoFilter based on cell value

Is is possible to write a macro that would AutoFilter a column by using the
exact or wildcard data entered in a cell; say "A1" instead of using an input
box? If so, what would the code look like?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default AutoFilter based on cell value

Assume you have data in Columns A:E and want to filter on column C for a
value that "contains" a string.

If you record a macro filtering on "contains" you will get similar to this.

Sub Macro2()
Range("A1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=3, Criteria1:="=*ay*"
End Sub

Change Selection.AutoFilter Field:=3, Criteria1:="=*ay*" to

Selection.AutoFilter Field:=3, Criteria1:="=*" & Range("H1").Value & "*"

Note that H1 is outside the range of data. A1 would be reserved for AF
header row so A1 might not be a good cell to reference.


Gord Dibben MS Excel MVP


On Mon, 16 Feb 2009 12:22:00 -0800, Tony S.
wrote:

Is is possible to write a macro that would AutoFilter a column by using the
exact or wildcard data entered in a cell; say "A1" instead of using an input
box? If so, what would the code look like?


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 60
Default AutoFilter based on cell value

Excellent Gord, Thanks for the guidance.

"Gord Dibben" wrote:

Assume you have data in Columns A:E and want to filter on column C for a
value that "contains" a string.

If you record a macro filtering on "contains" you will get similar to this.

Sub Macro2()
Range("A1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=3, Criteria1:="=*ay*"
End Sub

Change Selection.AutoFilter Field:=3, Criteria1:="=*ay*" to

Selection.AutoFilter Field:=3, Criteria1:="=*" & Range("H1").Value & "*"

Note that H1 is outside the range of data. A1 would be reserved for AF
header row so A1 might not be a good cell to reference.


Gord Dibben MS Excel MVP


On Mon, 16 Feb 2009 12:22:00 -0800, Tony S.
wrote:

Is is possible to write a macro that would AutoFilter a column by using the
exact or wildcard data entered in a cell; say "A1" instead of using an input
box? If so, what would the code look like?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofilter using cell reference Eliott Excel Worksheet Functions 1 April 23rd 08 01:14 PM
vlookup based on results from autofilter Christa Excel Worksheet Functions 3 April 10th 08 06:16 PM
2007 Autofilter worse than 2003 Autofilter jsky Excel Discussion (Misc queries) 9 October 31st 07 12:14 AM
Autofilter using the contents of a particular cell mathew Excel Discussion (Misc queries) 8 September 12th 06 10:43 PM
Autofilter in a single cell Turquoise_dax Excel Discussion (Misc queries) 2 June 21st 06 04:04 PM


All times are GMT +1. The time now is 08:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"