Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Oct 2008
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Part of of the VBA code that I have is to set up a formated current date in G2. The code that I have is:

    Range("G2") = "=now()"
    Range("G2").NumberFormat = "d-mmm-yyyy, h:mm AM/PM"
    Range("G2").Value = Range("G2")

    This works, but I'm sure there is a better way to do this and in a single line of code. Can anyone help me figure it out?

  2. #2
    5 Star Lounger
    Join Date
    Aug 2004
    Location
    Connecticut, USA
    Posts
    816
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can shorten it to two lines. I don't think it's possible to do it in one command since you are performing two operations. One being adding the date, the second being the formatting of the date.

    Range("G2") = Now()
    Range("G2").NumberFormat = "d-mmm-yyyy, h:mm AM/PM"

Posting Permissions

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