Solved

Autofilter on date in cell

Posted on 2007-04-08
3
218 Views
Last Modified: 2013-11-25
Hi, I have a macro that prompts the user to input the date they'd like to filter the data on.  The date they enter is placed in K3 on the worksheet.   All works well except the column is filtered on m/dd/yy.  I need dd/mm/yy.

Sub PAWPSCLOSEDU()
   Dim Date1 As Date
  Date1 = InputBox("Enter date for 'Closed since', eg 01/01/07", "Input Date")
   On Error GoTo 0
 If Date1 = #12:00:00 AM# Then
  MsgBox "No date entered"
  Exit Sub
 End If
 Range("k3").Value = Date1
 Range("k3").NumberFormat = "dd/mm/yy"
 
   Application.ScreenUpdating = False
      Range("k3").Select
     Selection.AutoFilter Field:=9, Criteria1:=">=" & Worksheets("Priority Action Work Plans").Range("k3").Value
    ActiveCell.FormulaR1C1 = Date1
    Range("A1").Select
    ActiveCell.Offset(4, 0).Select
    Application.ScreenUpdating = True
End Sub

Many thanks for any ideas.
0
Comment
Question by:Dalevb
  • 2
3 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 18873015
Try it like this. I added code to convert the date format from dd/mm/yy into mm/dd/yy. VBA uses the American style dates, which is why your original macro didn't work as intended.

Sub PAWPSCLOSEDU()
Dim Date1 As Date
Dim vDate As Variant
Dim sDate As String
sDate = InputBox("Enter date for 'Closed since', eg 01/01/07", "Input Date")
On Error GoTo 0
If sDate = "" Then
    MsgBox "No date entered"
    Exit Sub
End If

vDate = Split(sDate, "/")
If UBound(vDate) = 0 Then vDate = Split(sDate, "-")
Date1 = DateSerial(vDate(2), vDate(1), vDate(0))

Range("k3").Value = Date1
Range("k3").NumberFormat = "dd/mm/yy"

Application.ScreenUpdating = False
Range("k3").Select
Selection.AutoFilter Field:=9, Criteria1:=">=" & Worksheets("Priority Action Work Plans").Range("k3").Value
ActiveCell.FormulaR1C1 = Date1
Range("A1").Select
ActiveCell.Offset(4, 0).Select
Application.ScreenUpdating = True
End Sub


Brad
0
 
LVL 81

Expert Comment

by:byundt
ID: 18874022
Dalevb,
Thanks for the grade!
Brad
0
 

Author Comment

by:Dalevb
ID: 18874389
Thank you Brad!  (Not sure if my previous comment submitted properly.)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question