Consulting

Results 1 to 3 of 3

Thread: Date conundrum

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Date conundrum

    For UK language setup only

    Try the following. Enter 1/2/06 in the input box

    [VBA]Sub InsertDate()
    Range("A1:A2").NumberFormat = "dd mmmm yyyy"
    tmp = InputBox("Insert date")
    [A1] = tmp
    [A2] = DateValue(tmp)
    End Sub
    [/VBA]
    My Result
    A1 = 02 January 2006
    A2 = 01 February 2006
    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'

  2. #2
    VBAX Tutor Philcjr's Avatar
    Joined
    Jul 2005
    Location
    Bedminster, NJ
    Posts
    208
    Location
    I tried it and got:
    A1 = 02 January 2006
    A2 = 02 January 2006

    I had to add
    Dim tmp as Date

    Hope this helps, Phil

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by mdmackillop
    For UK language setup only

    Try the following. Enter 1/2/06 in the input box

    [VBA]Sub InsertDate()
    Range("A1:A2").NumberFormat = "dd mmmm yyyy"
    tmp = InputBox("Insert date")
    [A1] = tmp
    [A2] = DateValue(tmp)
    End Sub
    [/VBA]
    My Result
    A1 = 02 January 2006
    A2 = 01 February 2006
    VBA talks American English Malcolm. You always have to cast dates for Excel.

    For example

    [vba]
    [A1] = CDate(tmp)
    [/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
  •