Marco with autofilter

A

avilla

Hi can anybody help

I have used the following code to enter a specific date in an inputbo
that looks at the autofilter column and displays the result relevent t
the date entered on the worksheet. I am new to this and keep gettin
errors that I am unable to solve. Any help would be fantastic.


Sub Enter_Date()
Dim mydate As Date
Selection.AutoFilter Field:=9, Criteria1:=">=mydate"
mydate = InputBox("Enter Month in MMM-YY format")
If mydate >= InputBox Then
If IsDate(mydate) Then
MsgBox "Continue the macro"
Else
MsgBox "You didn't enter a date"
End If
End If
End Su
 
B

Bob Phillips

This code is a bit odd. What exactly do you want to do, and what dates are
being stored?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
A

avilla

I have a column that holds invoice dates for one of our company depots
and i want to create a macro that will allow a user to enter a dat
into a input box and filter the sale orders to show only them with tha
date enter by the user.

I am new to creating vba and macros and have just got this around m
head thank
 
B

Bob Phillips

But why do you ask for dates in mmm-yy format, is it just shown that way or
do you really store that way?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
D

Dave Peterson

I'd ask for a 4 digit year--sometimes excel sees two digits as the day of the
month.

But this seemed to work ok for me:

Option Explicit
Sub Enter_Date()
Dim myDate As Date

myDate = InputBox("Enter Month in MMM-YYYY format")

If IsDate(myDate) Then
'ok
Else
MsgBox "Please try again later"
Exit Sub
End If

Selection.AutoFilter Field:=9, Criteria1:=">=" & myDate

End Sub

But sometimes VBA doesn't play well with dates.

When you go back to check the filter and it doesn't look right, try this line:

Selection.AutoFilter Field:=9, Criteria1:=">=" & clng(myDate)

Sometimes comparing as an integer helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top