Consulting

Results 1 to 7 of 7

Thread: Solved: date format problem with macro....

  1. #1

    Solved: date format problem with macro....

    Hi there

    I have this bit of code which is run on clicking on a control, which enters the user entered date into a particular cell. The cell (K3) has been formatted to the British date system DD-MM-YR. Yet if the user enters 04-01-08 (for 4th Jan 2008), the macro enters 1st of April into the cell!

    Hope you can help...

    Thanks
    Sunil

    [VBA]Sub PostTrackStatus01()
    Dim mKey As String
    Application.ScreenUpdating = False
    Sheets("1TL").Unprotect Password:=pWord
    Sheets("1TR").Unprotect Password:=pWord
    Sheets("1A").Unprotect Password:=pWord
    mKey = InputBox("Enter date up to which you are posting progress in the format: DD-MM-YR", _
    "Enter Date")

    Worksheets("1TR").Range("K3").Value = mKey

    End Sub[/VBA]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    DD-MM-YY
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Sorry that was my typing error. the cell is acutally in a standard British date format DD-MM-YY. the relevant code i'm using is:
    [VBA]Sub PostTrackStatus01()
    Dim mKey As String
    mKey = InputBox("Enter date up to which you are posting progress in the format: DD-MM-YY", _
    "Enter Date")

    Worksheets("1TR").Range("K3").Value = mKey

    End Sub[/VBA]
    ..but it still assumes the date is being entered in American format...
    Thanks
    S

  4. #4
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    You could trick it with

    Format(mKey,"MM/DD/YY")

    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  5. #5
    Not sure where to insert that exactly.. I did the following but it didn't work...
    [vba]Sub PostTrackStatus01()
    Dim mKey As String

    Format (mKey = "MM/DD/YY")
    mKey = InputBox("Enter date up to which you are posting progress in the format: DD-MM-YY", _
    "Enter Posting Date")

    Worksheets("1TR").Range("J3").Value = mKey
    Worksheets("1ID").Range("F3").Value = mKey
    End Sub[/vba]

  6. #6
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    [vba]Sub PostTrackStatus01()
    Dim mKey As String
    mKey = InputBox("Enter date up to which you are posting progress in the format: DD-MM-YY", _
    "Enter Date")

    Worksheets("1TR").Range("K3").Value = Format(mKey,"MM/DD/YY")

    End Sub[/vba]
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  7. #7
    Thanks - that worked!
    S

Posting Permissions

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