Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel vba Custom Filter

Status
Not open for further replies.

arvarr

MIS
Nov 24, 2009
260
AU
Hi
I am trying to write a macro for custom filter but not sure what is wrong. Any help would be greatly appreciated.
Thanks.

Below is data in worksheet
Column A Column B
Month 1/08/2010 (Have format it to mm/dd/yyyy)

Date Hrs Person
1/02/2010 10 Dave
2/02/2010 5 Mike
3/08/2010 2 Greg
31/08/2010 6 Anthony
2/09/2010 3 Jack


Sub test()

Dim Month As String
Dim Aug09a As String
Dim Aug09b As String

Month = Format(Range("B1"), "mm/dd/yyyy")
Aug09a = Format("08-01-2010", "mm/dd/yyyy")
Aug09b = Format("08-31-2010", "mm/dd/yyyy")

If Month = Aug09a Then

Selection.AutoFilter Field:=1, Criteria1:=">=" & Aug09a, Operator:=xlAnd _
, Criteria2:="<=" & Aug09b

Else
End If
End Sub

 


Hi,

Please post VBA Questions in forum707.

Turn on your macro recorder and record assigning the AutoFilter as you desire.

Post back in forum707 with your recorded code and your question, for help if so needed.

HINT: the Format function returns a STRING and not a DATE.

faq68-5827

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top