Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How To Create a Value Based Upon The Contents of A List | Excel Worksheet Functions | |||
Create filename based on cell contents | Excel Worksheet Functions | |||
how do i create a macro that would check the contents of cells | Excel Discussion (Misc queries) | |||
how do i create a macro that would check the contents of cells | Excel Discussion (Misc queries) | |||
Create filename based on cell contents | Excel Programming |