filtering column using date

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Filtering column using date format from input box | Excel forum

Filtering column using date format from input box | Excel forum

resolvedResolved · Medium Priority · Version 2007

Ian has attended:
Excel VBA Intro Intermediate course

Filtering column using date format from input box

I am using the following code to try and filter and copy on a coulmn that has a date format in using adate value added using an input box it works for dates which are in double figues i.e 10 plus but for single figure date it returns no data in the filter I ahve tried various date formats but to no avail.

Option Explicit
Public TSNAME As String
Dim Repdate As Date



Sub CREATE2()

TSNAME = InputBox("Enter Date For New Traffic Sheet as follows DD-MM-YYYY")

Sheets.Add after:=ActiveWorkbook.Sheets(Sheets.Count)

ActiveSheet.Name = ("Traffic Sheet") & " " & TSNAME

Call copetemp

End Sub

Sub copetemp()

Application.ScreenUpdating = False
Sheets(" Traffic Sheet Template").Visible = True
Sheets(" Traffic Sheet Template").Select

Range("A1:K2").Select

Selection.Copy

Worksheets(Worksheets.Count).Select

ActiveSheet.Paste

Repdate = InputBox("Enter Collection Date")

Sheets("Data Sheet").Select

Columns("N:N").NumberFormat = "mm/dd/yyyy"
'Range("A1").Select
Range("A:W").AutoFilter field:=14, Criteria1:=Repdate


Range("N3:N" & Range("A65536").End(xlUp).Row).Select
Selection.Copy
Worksheets(Worksheets.Count).Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues

RE: Filtering column using date format from input box

Hi Ian

Thanks for getting in touch. You should note that VBA stores dates in US format, e.g. "4/24/2012" for 24th April 2012. I can see you change the NumberFormat appropriately but do double check what's happening.

Does this shed any light on it? If not, try stepping through the code with the Locals Window enabled (View > Locals).

If this is the case, try using the Format command on the repdate, e.g.

repdate = InputBox("Enter Collection Date")

Format (repdate, "mm/dd/yyyy")

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Editing Formulas in Excel Cells

Although people like to edit a formula in the Formula bar, you can also edit a formula in the cell.

To do this select the cell and press "F2". This puts Excel into Edit mode, and you can move around in the cell and make any necessary changes.

Double-clicking the cell also puts Excel in Edit mode.

View all Excel hints and tips


Server loaded in 0.09 secs.