Consulting

Results 1 to 9 of 9

Thread: date in vba when paste defaults to american

  1. #1

    date in vba when paste defaults to american

    [VBA]Sub SetDate()
    Dim strFileName As String
    Set WS = Sheets("ZF")
    WS.Range("B:B").Replace What:=".", Replacement:="/", LookAt:=xlPart
    End Sub[/VBA]

    hi im using this to change Date in excel , when i paste it to my workbook it defaults to american date format is there something im missing ??

    and this to copy and paste

    [VBA]Set wkbkZF = Workbooks("ZF.xls")
    Set wkbkSS = Workbooks("IMF stage starts WK " & CStr(VBAWeekNum(Now(), 1)) & "." _
    & CStr(Application.WorksheetFunction.Weekday(Now())) - 1 & ".xls")
    Set tgt = wkbkSS.Sheets("Everything").Range("B3")
    With wkbkZF.Sheets(1)
    Set MyRange = .Range("B5:M" & .Cells(Rows.Count, 2).End(xlUp).Row)
    End With
    MyRange.Copy Destination:=tgt[/VBA]

    Many thanks

    Merc

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    try this after your copy and paste [VBA]tgt.value = Format(tgt.value, "dd/mm/yyyy")[/VBA]not tested but should do the trick!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Simon

    not it is still doing same

    05/01/2007 05/02/2007
    should be 01/05/2007 & 02/05/2007

    Merc

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Can't you format your desination range manually...permanantly?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Of course you can click column B (on the destination sheet) and then right click, format and format to the required date for the required contry format, but if you really want it in VBA:
    [VBA]
    Columns("B:B").Select
    Selection.NumberFormat = "dd/mm/yyyy;@"
    [/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    Lucas

    No it still dong same , any help would be appreciated

    Merc

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    without reconstructing the workbooks you might try not copying...
    instead of this:
    [VBA]MyRange.Copy Destination:=tgt [/VBA]
    maybe something like this:
    [VBA]
    tgt = MyRange
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I notice that in SetDate sub you are only replaceing a . with a / what if you format it after you do that?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    [VBA]Sub switch_day_month()
    Dim v_date() As String
    v_date = Split(ActiveCell.Value, ".")
    ActiveCell.Value = v_date(1) & "/" & v_date(0) & "/" & v_date(2)
    End Sub[/VBA]

Posting Permissions

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