Solved

Autofilter on date in cell

Posted on 2007-04-08
3
219 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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