Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Create a macro to run autofilter based on contents of 2 cells

I have a list of dates in column A, starting in cell A3 upto cell A1002. I
have the autofilter in place for column A. I want to run a macro that will
filter these dates to show only the ones that are equal or greater than the
first date that is in cell A1, and also that are equal or less than the
second date in cell B1.
I can filter the information using the custom part of the autofilter, but
I'd rather be able to type the to and from dates in the two cells stated and
press a button to run the macro.

I hope that makes sense. Any help would be greatly appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 341
Default Create a macro to run autofilter based on contents of 2 cells

I hope that your cell A3 contains some header like "Date".

Insert this code in a module. Instructions for how to insert code in a
regular module are here http://www.contextures.com/xlvba01.html#Top

Sub TryThis()

Range("A3").AutoFilter Field:=1, Criteria1:="=" & Range("A1").Value,
Operator:=xlAnd, Criteria2:="<=" & Range("B1").Value

End Sub

Now you can put a button into your sheet to run this code.
The easiest way is to do Edit Toolbars Forms. From there you can drag
and drop a button into your sheet (put it right at the top otherwise you
won't see it when the filter is applied). Excel kindly asks you to link it
to a macro, and you can just choose the TryThis macro.


--
Allllen


"Syndrome" wrote:

I have a list of dates in column A, starting in cell A3 upto cell A1002. I
have the autofilter in place for column A. I want to run a macro that will
filter these dates to show only the ones that are equal or greater than the
first date that is in cell A1, and also that are equal or less than the
second date in cell B1.
I can filter the information using the custom part of the autofilter, but
I'd rather be able to type the to and from dates in the two cells stated and
press a button to run the macro.

I hope that makes sense. Any help would be greatly appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Create a macro to run autofilter based on contents of 2 cells

Hi,

Thanks for this but I can't seem to get the macro to work. I've copied the
code to a new module within the spreadsheet. As my header is in cell A2 I
amended the macro accordingly.

When I run the macro I get the following message:-

Compile error
Syntax error

The first line of code below the sub heading is highlighted.

Hope this makes sense and any further help would be appreciated.

Thanks

"Allllen" wrote:

I hope that your cell A3 contains some header like "Date".

Insert this code in a module. Instructions for how to insert code in a
regular module are here http://www.contextures.com/xlvba01.html#Top

Sub TryThis()

Range("A3").AutoFilter Field:=1, Criteria1:="=" & Range("A1").Value,
Operator:=xlAnd, Criteria2:="<=" & Range("B1").Value

End Sub

Now you can put a button into your sheet to run this code.
The easiest way is to do Edit Toolbars Forms. From there you can drag
and drop a button into your sheet (put it right at the top otherwise you
won't see it when the filter is applied). Excel kindly asks you to link it
to a macro, and you can just choose the TryThis macro.


--
Allllen


"Syndrome" wrote:

I have a list of dates in column A, starting in cell A3 upto cell A1002. I
have the autofilter in place for column A. I want to run a macro that will
filter these dates to show only the ones that are equal or greater than the
first date that is in cell A1, and also that are equal or less than the
second date in cell B1.
I can filter the information using the custom part of the autofilter, but
I'd rather be able to type the to and from dates in the two cells stated and
press a button to run the macro.

I hope that makes sense. Any help would be greatly appreciated.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Create a macro to run autofilter based on contents of 2 cells

Further Update:

I tried putting the code all on one line rather than on two lines as posted
below. ( I pressed delete at the end of the first line of code). The Macro
then ran and filtered column A but but didn't show any filtered data, as
though the dates in cells A3 onwards were outside of the range of dates in
cells A1 & B1.

Thanks again

"Syndrome" wrote:

Hi,

Thanks for this but I can't seem to get the macro to work. I've copied the
code to a new module within the spreadsheet. As my header is in cell A2 I
amended the macro accordingly.

When I run the macro I get the following message:-

Compile error
Syntax error

The first line of code below the sub heading is highlighted.

Hope this makes sense and any further help would be appreciated.

Thanks

"Allllen" wrote:

I hope that your cell A3 contains some header like "Date".

Insert this code in a module. Instructions for how to insert code in a
regular module are here http://www.contextures.com/xlvba01.html#Top

Sub TryThis()

Range("A3").AutoFilter Field:=1, Criteria1:="=" & Range("A1").Value,
Operator:=xlAnd, Criteria2:="<=" & Range("B1").Value

End Sub

Now you can put a button into your sheet to run this code.
The easiest way is to do Edit Toolbars Forms. From there you can drag
and drop a button into your sheet (put it right at the top otherwise you
won't see it when the filter is applied). Excel kindly asks you to link it
to a macro, and you can just choose the TryThis macro.


--
Allllen


"Syndrome" wrote:

I have a list of dates in column A, starting in cell A3 upto cell A1002. I
have the autofilter in place for column A. I want to run a macro that will
filter these dates to show only the ones that are equal or greater than the
first date that is in cell A1, and also that are equal or less than the
second date in cell B1.
I can filter the information using the custom part of the autofilter, but
I'd rather be able to type the to and from dates in the two cells stated and
press a button to run the macro.

I hope that makes sense. Any help would be greatly appreciated.

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
How To Create a Value Based Upon The Contents of A List jeb Excel Worksheet Functions 2 February 18th 09 07:50 PM
Create filename based on cell contents JR Hester Excel Worksheet Functions 7 April 4th 07 11:34 PM
how do i create a macro that would check the contents of cells Jade Excel Discussion (Misc queries) 1 December 31st 05 01:37 AM
how do i create a macro that would check the contents of cells Jade Excel Discussion (Misc queries) 1 December 31st 05 12:48 AM
Create filename based on cell contents Rudy W Excel Programming 2 December 3rd 04 03:23 AM


All times are GMT +1. The time now is 06:44 PM.

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"