Home |
Search |
Today's Posts |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Autofilter Delema
Hi
Dim myDate as Variant myDate = Application.InputBox(prompt:="Please enter a date in the format dd\mm\yyyy", _ Type:=2) While myDate<FALSE do Selection.AutoFilter Field:=2, Criteria1:=myDate 'etc myDate = Application.InputBox(prompt:="Please enter a date in the format dd\mm\yyyy", _ Type:=2) Loop This will keep showing the input box until you click Cancel. regards Paul Tsunami3169 wrote: Thanks for the help. I'm also trying to loop this because this needs to be done for several dates. I've tried using Do Until, Loop with the Do Until in different spots (can you tell i'm a nubie?) hoping I would get them in the right spot. But nothing seemed to work. Any direction on using loops with input boxes? wrote: Hi You will need something like; Dim myDate as Variant myDate = Application.InputBox(prompt:="Please enter a date in the format dd\mm\yyyy", _ Type:=2) If myDate = False then Exit sub 'cancel clicked else Selection.AutoFilter Field:=2, Criteria1:=myDate 'etc end if The myDate variable is expecting a string (type 2). This is a beginning. The Autofilter searches on a STRING, so the input date format must be the same as is on the sheet. you must also error check the inputbox value to check it is the correct format. regards Paul Tsunami3169 wrote: Tsunami3169 wrote: My problem is I have a workbook that auto imports a text doc. I then run a macro to format the worksheet, data and set an auto filter. I filter column B to select the correct date which to copy the data needed. Is there a macro I can use to automate the auto filter using a pop up input box? So when a user inputs a date the data will be filtered by that date. I'm some what new to macros and have searched many web pages looking for an answer. Any help would be greatly appreciated. Oops I forgot to add the macro I currently use. This is what I currently use but it will only filter on yesterdays date. Selection.AutoFilter Field:=2, Criteria1:=Date - 1 Application.Goto Reference:="Data_Select" Selection.Copy |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Autofilter Delema
Thanks again for this starting point. I tweeked it a little to end the
loop and an error message if the person entered an incorrect date. Dim myDate As Variant myDate = Application.InputBox(prompt:="Please enter a date in the format dd\mm\yyyy", _ Type:=2) While myDate < False Do 'Start Do..Loop On Error GoTo InputError 'when error occurs InputError: MsgBox ("Select a different date") 'Copy selection Selection.AutoFilter Field:=2, Criteria1:=myDate Application.Goto Reference:="Data_Select" myDate = Application.InputBox(prompt:="Please enter a date in the format dd\mm\yyyy", _ Type:=2) Exit Do Loop Wend End Sub wrote: Hi Dim myDate as Variant myDate = Application.InputBox(prompt:="Please enter a date in the format dd\mm\yyyy", _ Type:=2) While myDate<FALSE do Selection.AutoFilter Field:=2, Criteria1:=myDate 'etc myDate = Application.InputBox(prompt:="Please enter a date in the format dd\mm\yyyy", _ Type:=2) Loop This will keep showing the input box until you click Cancel. regards Paul Tsunami3169 wrote: Thanks for the help. I'm also trying to loop this because this needs to be done for several dates. I've tried using Do Until, Loop with the Do Until in different spots (can you tell i'm a nubie?) hoping I would get them in the right spot. But nothing seemed to work. Any direction on using loops with input boxes? wrote: Hi You will need something like; Dim myDate as Variant myDate = Application.InputBox(prompt:="Please enter a date in the format dd\mm\yyyy", _ Type:=2) If myDate = False then Exit sub 'cancel clicked else Selection.AutoFilter Field:=2, Criteria1:=myDate 'etc end if The myDate variable is expecting a string (type 2). This is a beginning. The Autofilter searches on a STRING, so the input date format must be the same as is on the sheet. you must also error check the inputbox value to check it is the correct format. regards Paul Tsunami3169 wrote: Tsunami3169 wrote: My problem is I have a workbook that auto imports a text doc. I then run a macro to format the worksheet, data and set an auto filter. I filter column B to select the correct date which to copy the data needed. Is there a macro I can use to automate the auto filter using a pop up input box? So when a user inputs a date the data will be filtered by that date. I'm some what new to macros and have searched many web pages looking for an answer. Any help would be greatly appreciated. Oops I forgot to add the macro I currently use. This is what I currently use but it will only filter on yesterdays date. Selection.AutoFilter Field:=2, Criteria1:=Date - 1 Application.Goto Reference:="Data_Select" Selection.Copy |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
excel 2007 autofilter change to 2003 autofilter functionality? | Excel Discussion (Misc queries) | |||
2007 excel autofilter back to 2003 autofilter? | Excel Discussion (Misc queries) | |||
2007 excel autofilter change back to 2003 autofilter? | Excel Discussion (Misc queries) | |||
2007 Autofilter worse than 2003 Autofilter | Excel Discussion (Misc queries) | |||
How to Sort within AutoFilter with Protection on (and AutoFilter . | Excel Discussion (Misc queries) |