Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Macro that AutoFilters based on Cell value

I want to write a Macro that will run an autofilter based on a cell value.

Ex:
Let's say cell A1 = red and I have a list of cars with their color beside
it. When I run the macro, I want it to use AutoFilter to show all the red
cars. However, if I change A1 to blue, when the macro is run, I want it to
show all the blue cars.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro that AutoFilters based on Cell value

The following line in your macro will do the trick:-

Selection.AutoFilter Field:=2, Criteria1:=colour (colour is the variable for
the value of A1 in)

Change the field number as required - if your date filter is on columns E to
X and the colour is in H then the field number becomes 4 etc

I would recommend putting this line in at the start of the macro:-

Selection.AutoFilter Field:=2

Again, where the field number is your column - this will reset all filters
to show all records.



"Al" wrote in message
...
I want to write a Macro that will run an autofilter based on a cell value.

Ex:
Let's say cell A1 = red and I have a list of cars with their color beside
it. When I run the macro, I want it to use AutoFilter to show all the red
cars. However, if I change A1 to blue, when the macro is run, I want it
to
show all the blue cars.

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Macro that AutoFilters based on Cell value

Looks like that'd work, but how do I declare a the cell as a variable?
Sorry, I'm new to writing macros.


"Neil Kennedy" wrote:

The following line in your macro will do the trick:-

Selection.AutoFilter Field:=2, Criteria1:=colour (colour is the variable for
the value of A1 in)

Change the field number as required - if your date filter is on columns E to
X and the colour is in H then the field number becomes 4 etc

I would recommend putting this line in at the start of the macro:-

Selection.AutoFilter Field:=2

Again, where the field number is your column - this will reset all filters
to show all records.



"Al" wrote in message
...
I want to write a Macro that will run an autofilter based on a cell value.

Ex:
Let's say cell A1 = red and I have a list of cars with their color beside
it. When I run the macro, I want it to use AutoFilter to show all the red
cars. However, if I change A1 to blue, when the macro is run, I want it
to
show all the blue cars.

Thanks




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro that AutoFilters based on Cell value

We all had to start somewhere :)

Try something like this:-

Sub Macro1()

Dim colour As String

Selection.AutoFilter Field:=1 ********amend as required

Range("A1").Select
colour = ActiveCell.Value

Selection.AutoFilter Field:=1, Criteria1:=colour ********amend as required

Range("A1").Select

End Sub


"Al" wrote in message
...
Looks like that'd work, but how do I declare a the cell as a variable?
Sorry, I'm new to writing macros.


"Neil Kennedy" wrote:

The following line in your macro will do the trick:-

Selection.AutoFilter Field:=2, Criteria1:=colour (colour is the variable
for
the value of A1 in)

Change the field number as required - if your date filter is on columns E
to
X and the colour is in H then the field number becomes 4 etc

I would recommend putting this line in at the start of the macro:-

Selection.AutoFilter Field:=2

Again, where the field number is your column - this will reset all
filters
to show all records.



"Al" wrote in message
...
I want to write a Macro that will run an autofilter based on a cell
value.

Ex:
Let's say cell A1 = red and I have a list of cars with their color
beside
it. When I run the macro, I want it to use AutoFilter to show all the
red
cars. However, if I change A1 to blue, when the macro is run, I want
it
to
show all the blue cars.

Thanks






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
Macro based on Cell Value NPell Excel Worksheet Functions 2 June 17th 08 04:50 PM
Run macro based on cell value nowfal[_3_] Excel Programming 2 September 15th 04 10:39 AM
Please help! Macro to change cell contents based on cell to the left Jennifer[_8_] Excel Programming 7 March 4th 04 01:06 AM
Run A Macro based on changes in cell Pete Excel Programming 2 December 2nd 03 03:08 PM
Userforms and autofilters - Autofilters don't seen to work with userform No Name Excel Programming 3 August 28th 03 05:42 PM


All times are GMT +1. The time now is 07:47 AM.

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

About Us

"It's about Microsoft Excel"