Solved

Autofilter on date in cell

Posted on 2007-04-08
3
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

617 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