Consulting

Results 1 to 5 of 5

Thread: Date Problem

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Date Problem

    All

    I am using the code below to autofilter a date

    Can anyone tell me why this still formats my date in the american format and not the uk ?

    Cheers

    Gibbo

    [VBA] Workbooks("Outstanding").Sheets("Data").Range("B8:L" & iLastRow).AutoFilter _
    Field:=10, Criteria1:=">=" & Format(txtInputFrom.Text, "dd/mm/yyyy") [/VBA]

    I ve tried swapping my format around to mm/dd/yyyy and that works for me but was wondering is this the only way to do this or is there a better way?

  2. #2
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Gibbo,

    Can you try formatting as dd-mmm-yyyy, or yyyy-mm-dd?

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by gibbo1715
    All

    I am using the code below to autofilter a date

    Can anyone tell me why this still formats my date in the american format and not the uk ?
    I am not clear Gibbo. What exactly is being formatted? As I see it, you are filtering by date. Are you saying that UK style dates in your list appear as US style dates after filtering?

  4. #4
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Hi Bob

    Yes, what im doing is via my user form invoking the auto filter on a different workbook and then filtering the date field and copying to a new workbook.

    My textbox input is in the format dd/mm/yyyy

    When i check my data the custom field on the autofilter swapps the dd/mm to mm/dd, i have found by formatting my text box as mm/dd/yyyy in my code solves the problem.

    I was just wondering why it does that, my excel and PC are set up for UK dates?

    Cheers

    Gibbo

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by gibbo1715
    Hi Bob

    Yes, what im doing is via my user form invoking the auto filter on a different workbook and then filtering the date field and copying to a new workbook.

    My textbox input is in the format dd/mm/yyyy

    When i check my data the custom field on the autofilter swapps the dd/mm to mm/dd, i have found by formatting my text box as mm/dd/yyyy in my code solves the problem.

    I was just wondering why it does that, my excel and PC are set up for UK dates?

    Cheers

    Gibbo
    Gibbo,

    The fundamental problem is that VBA talks US style dates, regardless of whatever your settings may say.

    Formatting is US style is one solution, another maybe to comapre the range to

    Str(CDbl(TxtInputFrom.Text))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •