+ Reply to Thread
Results 1 to 2 of 2

Macro changing dates to American from UK

  1. #1
    Registered User
    Join Date
    01-14-2013
    Location
    Derby
    MS-Off Ver
    Excel 2007
    Posts
    22

    Macro changing dates to American from UK

    I have a macro which works perfectly.

    However, when I run it it is switching the dates from the original UK format ie 15/03/2014 to American format ie 03/15/2014.

    Below is the script -

    Sub Copy_To_late()

    Dim My_Range As Range, x, i&, dic As Object, MyPath$, foldername$, Ms As Worksheet, FileExtStr$
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    MyPath = "P:\geoff allen\"
    If Right(MyPath, 1) <> "\" Then
    MyPath = MyPath & "\"
    End If
    foldername = MyPath & Format(Now, "yyyy-mm-dd hh-mm-ss") & "\"
    MkDir foldername
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = 1

    With Sheets("Sheet1").Range("A1:cr" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row)
    x = .Value
    For i = 2 To UBound(x)
    If Len(x(i, 1)) Then
    If Not dic.Exists(Trim$((x(i, 1)))) Then
    dic.Item(Trim$(x(i, 1))) = Empty

    .AutoFilter 1, "=" & Replace(Replace(Replace(x(i, 1), "~", "~~"), "*", "~*"), "?", "~?")

    Set Ms = Workbooks.Add(xlWBATWorksheet).Worksheets(1)
    .SpecialCells(xlCellTypeVisible).Copy

    With Ms
    .Range("a1").PasteSpecial xlPasteValues
    .Range("a1").PasteSpecial xlPasteFormats
    .Columns.AutoFit
    End With
    Application.CutCopyMode = False
    On Error Resume Next
    Ms.Parent.SaveAs foldername & x(i, 1) & ".csv", FileFormat:=xlCSV

    Ms.Parent.Close False
    On Error GoTo 0

    .AutoFilter Field:=1
    End If
    End If
    Next i
    End With

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub

    Really frustrating me as I need this to work ASAP.

    Would appreciate any assistance provided.

    Thanks,

    Geoff

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Macro changing dates to American from UK

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Userform changing date format to American
    By JamesT1 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-11-2013, 10:05 AM
  2. Macro saves my CSV file with dates in American format
    By JulietMikeMike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2013, 10:06 PM
  3. Why is the date changing to American Format
    By darbid in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-07-2010, 10:00 AM
  4. Macro Dates - American or English
    By simmo86 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2010, 09:03 AM
  5. dates on a userform are american!!!
    By excely in forum Excel General
    Replies: 1
    Last Post: 04-14-2008, 07:31 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1