98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum 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
Resolved · 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 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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Editing Formulas in Excel CellsAlthough people like to edit a formula in the Formula bar, you can also edit a formula in the cell. |