Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Jeff
 
Posts: n/a
Default Macro for autofilter using variables declared in worksheet

Hi,
I have recorded the following macro which works fine

Sub Filter1()
'
' FilterbyProduct Macro
' Basis for Filter based on criteria as a range entered in sheet
'
Selection.AutoFilter Field:=3, Criteria1:="=15", Operator:=xlAnd, _
Criteria2:="<=20"
Selection.AutoFilter Field:=2, Criteria1:="=10", Operator:=xlAnd
Range("C3").Select
End Sub

I always intended for the variables to actually be declared in the worksheet
because the filters are always based on (first filter) groups of products in
the format "=x" and "<=y", with the second filter "=z".
I haven't been able to substitute the value of the criteria contained in
cells Main!A1,A2 and A3 instead of the "fixed" values in the recorded macro
i.e 15,20 and 10 (shown above).

Can anyone help.
sincerely
Jeff



  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Change the criterial portion from this:
Criteria1:="=15"
to:
Criteria1:=""&worksheets("main").range("a1").valu e



Jeff wrote:

Hi,
I have recorded the following macro which works fine

Sub Filter1()
'
' FilterbyProduct Macro
' Basis for Filter based on criteria as a range entered in sheet
'
Selection.AutoFilter Field:=3, Criteria1:="=15", Operator:=xlAnd, _
Criteria2:="<=20"
Selection.AutoFilter Field:=2, Criteria1:="=10", Operator:=xlAnd
Range("C3").Select
End Sub

I always intended for the variables to actually be declared in the worksheet
because the filters are always based on (first filter) groups of products in
the format "=x" and "<=y", with the second filter "=z".
I haven't been able to substitute the value of the criteria contained in
cells Main!A1,A2 and A3 instead of the "fixed" values in the recorded macro
i.e 15,20 and 10 (shown above).

Can anyone help.
sincerely
Jeff


--

Dave Peterson
  #3   Report Post  
Jeff
 
Posts: n/a
Default

Many thanks. I'm impressed. I spent hours trying different combinations of
things.
You (and other poster repliers) provide much valued education value to us
ordinary excel users.
sincerely

Jeff

"Dave Peterson" wrote in message
...
Change the criterial portion from this:
Criteria1:="=15"
to:
Criteria1:=""&worksheets("main").range("a1").valu e



Jeff wrote:

Hi,
I have recorded the following macro which works fine

Sub Filter1()
'
' FilterbyProduct Macro
' Basis for Filter based on criteria as a range entered in sheet
'
Selection.AutoFilter Field:=3, Criteria1:="=15", Operator:=xlAnd, _
Criteria2:="<=20"
Selection.AutoFilter Field:=2, Criteria1:="=10", Operator:=xlAnd
Range("C3").Select
End Sub

I always intended for the variables to actually be declared in the
worksheet
because the filters are always based on (first filter) groups of products
in
the format "=x" and "<=y", with the second filter "=z".
I haven't been able to substitute the value of the criteria contained in
cells Main!A1,A2 and A3 instead of the "fixed" values in the recorded
macro
i.e 15,20 and 10 (shown above).

Can anyone help.
sincerely
Jeff


--

Dave Peterson



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
Help with macro looping and color query function kevinm Excel Discussion (Misc queries) 10 May 26th 05 01:25 AM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
Macro for multiple charts JS Excel Worksheet Functions 1 November 19th 04 03:44 AM


All times are GMT +1. The time now is 06:37 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"