Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Wildcards & Cell References in Filters

Hi, hopefully a quick answer is available to this, just having a mental blank:

This code succesfully finds all values that contain Australia. Easy.

Selection.AutoFilter
Selection.AutoFilter Field:=12, Criteria1:="=*Australia*", Operator:= _
xlAnd

However, i need to filter based on the value of a cell (not always Australia)

Selection.AutoFilter
Selection.AutoFilter Field:=12, Criteria1:="=*C12*", Operator:= _
xlAnd

Would\should\could this work?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Wildcards & Cell References in Filters

Example using just simple filter with wildcards:-

Dim selectCriteria
selectCriteria = "*" & Range("C12") & "*"
Selection.AutoFilter Field:=1, Criteria1:=selectCriteria

Build the criteria by concatenating the wild cards with the other data and
save in a variable. You don't use the quotes when replacing the criteria with
a variable even if that variable is a cell value.

Regards,

OssieMac

"D Zandveld" wrote:

Hi, hopefully a quick answer is available to this, just having a mental blank:

This code succesfully finds all values that contain Australia. Easy.

Selection.AutoFilter
Selection.AutoFilter Field:=12, Criteria1:="=*Australia*", Operator:= _
xlAnd

However, i need to filter based on the value of a cell (not always Australia)

Selection.AutoFilter
Selection.AutoFilter Field:=12, Criteria1:="=*C12*", Operator:= _
xlAnd

Would\should\could this work?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Wildcards & Cell References in Filters

Another example with an Or operator in the filter just in case you have
problems with it.

selectCriteria1 = "=*" & Range("C12") & "*"
selectCriteria2 = "=*" & Range("C13") & "*"

Selection.AutoFilter Field:=1, Criteria1:=selectCriteria1, _
Operator:=xlOr, Criteria2:=selectCriteria2

Regards,

OssieMac


"OssieMac" wrote:

Example using just simple filter with wildcards:-

Dim selectCriteria
selectCriteria = "*" & Range("C12") & "*"
Selection.AutoFilter Field:=1, Criteria1:=selectCriteria

Build the criteria by concatenating the wild cards with the other data and
save in a variable. You don't use the quotes when replacing the criteria with
a variable even if that variable is a cell value.

Regards,

OssieMac

"D Zandveld" wrote:

Hi, hopefully a quick answer is available to this, just having a mental blank:

This code succesfully finds all values that contain Australia. Easy.

Selection.AutoFilter
Selection.AutoFilter Field:=12, Criteria1:="=*Australia*", Operator:= _
xlAnd

However, i need to filter based on the value of a cell (not always Australia)

Selection.AutoFilter
Selection.AutoFilter Field:=12, Criteria1:="=*C12*", Operator:= _
xlAnd

Would\should\could this work?


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
convert relative cell references to absolute cell references via amacro? Dave F[_2_] Excel Discussion (Misc queries) 1 May 15th 08 04:43 PM
Filters/Circular References Miss Jones Excel Worksheet Functions 0 April 9th 08 07:41 PM
Using cell reference and wildcards in a forumla steev_jd Excel Discussion (Misc queries) 3 July 11th 06 03:28 PM
How to rename references from range names to cell references Abbas Excel Discussion (Misc queries) 1 May 24th 06 06:18 PM
Wildcards in other workbook cell refrence? Pootler Excel Worksheet Functions 1 June 2nd 05 05:55 PM


All times are GMT +1. The time now is 02:34 AM.

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"