• Help with VBA – Assign a current date

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Help with VBA – Assign a current date

    Author
    Topic
    #458501

    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?

    Viewing 0 reply threads
    Author
    Replies
    • #1153129

      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”

    Viewing 0 reply threads
    Reply To: Help with VBA – Assign a current date

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: