Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Date format (Excel 2003)

    Hi all,

    I'm trying to input a date from a Time Picker control, I have a number of cells that calls for this and like to able to input the date directly into the cell. Within the cell I have two characters that I would like to keep, I can't get the date to be a show a long form, such as dd-mmm-yy. What I get is the first 2 characters that I want then I get a date serial.

    Private Sub CommandButton1_Click()
    Dim v As String
    Dim W As String
    W = ActiveCell.Value
    Wx = Mid(W, 1, 2)
    v = DTPicker1.Value
    ActiveCell.Value = Wx & " " & Format(v, yy - mmm - dd)
    Unload UserForm1
    UserForm1.Hide
    End Sub

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Date format (Excel 2003)

    Does it work with quotes around it:

    <pre>ActiveCell.Value = Wx & " " & Format(v, "yy - mmm - dd")</pre>


    Steve

  3. #3
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: Date format (Excel 2003)

    Thanks Steve.

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Date format (Excel 2003)

    As a tip, if you went in VB to:
    Tools - options - editor (tab)
    and checked: "require variable declaration"
    [I strongly recommend this for a variety of reasons]

    you would have discovered that your Line:
    <pre>ActiveCell.Value = Wx & " " & Format(v, yy - mmm - dd)</pre>


    was interpreting yy, mmm, and dd as variables. Since they were not set with any numbers they are all interpreted as zero (since you use them mathematicall due to the negative signs. Thus your line is equivalent to:
    <pre>ActiveCell.Value = Wx & " " & Format(v, 0 - 0- 0)</pre>


    which is:
    <pre>ActiveCell.Value = Wx & " " & Format(v, 0)</pre>


    which will give the value in Wx and the serialdate (the date formatted with no decimal points.

    Steve

Posting Permissions

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