View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] paul.robinson@it-tallaght.ie is offline
external usenet poster
 
Posts: 789
Default 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