Consulting

Results 1 to 3 of 3

Thread: Format isn't working

  1. #1

    Format isn't working

    I don't understand why it isn't working
    [VBA]Sub test()
    Dim sheet As Worksheet
    Dim today As Date

    today = Format(Now, "mm-dd")
    Debug.Print today

    For Each sheet In ActiveWorkbook.Sheets
    'Debug.Print sheet.Name
    Next sheet

    End Sub
    [/VBA]
    Shouldn't the output be 04-18? Instead I'm getting 4/18/2012. What am I missing here?

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    When I change the object from Date to Variant or String, I get the correct output.

    David


  3. #3
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    Yeah that makes since the format function returns a string not a date.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

Posting Permissions

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