Consulting

Results 1 to 7 of 7

Thread: date as integer

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    date as integer

    hello
    the aim of the following code is to present a date number in comment while presenting the date in cell.
    [VBA]
    Dim cm As Comment
    Dim c As Range
    For Each c In selection.Cells
    c.clearcomments
    If Not IsEmpty(c) And IsDate(c) Then
    With c.AddComment
    .Text Text:="day number is:" & c.Value
    .Shape.TextFrame.AutoSize = True
    End With
    End If
    Next c

    [/VBA]
    is it possible to present information about a cell's content in a comment using a differnt number format?.
    of instance - 21\11\2036 is day number 50000.

    thanks
    moshe

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Is the date in the cell formatted as a date?

    If it is then use c.Text rather than c.Value.

    That should return the cell contents as you have it formatted.

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You can format the number:

    [vba]
    .Text Text:="day number is: " & Format(c.Value,"dd\mm\yyyy")
    [/vba]

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by DRJ
    [vba]"dd\mm\yyyy"[/vba]
    ??

    Wouldn't it be "dd/mm/yyyy"??

  5. #5
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    I just went of the format of the date in the original post. If you want to get technical it should be mm/dd/yyyy anyway.

  6. #6
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    .. unless you're on the other side of the pond.. which moshe is..

  7. #7
    VBAX Regular
    Joined
    May 2004
    Location
    Adelaide, Australia
    Posts
    28
    Location
    Perhaps to consider:

    .Value (is dependant on your windows reginal shortdate)
    .Text (reflects the .value status)

    .Value2 (returns the true date serial number)

    My point being if the cell is really formatted for a date then .Value2 will give you the exact serial number. Clng.Value should also work.

Posting Permissions

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