today code in vba

  • Thread starter Thread starter MPB
  • Start date Start date
M

MPB

Good evening all

I am after some simple code to apply to a CommandButton1_Click(),
where when the button is clicked, today's date is inserted into the active cell.
(Though I do require this date to then be fixed, and not change the following day)

Any help most appreciated.
Thank you
Mathew
 
Mathew,

Private Sub CommandButton1_Click()
Worksheets("yoursheetname").Range("A1") = Now
End Sub

You can replace the "Now" with something like:
Format(Now, "m/d/yy")
or whatever format you'd like it to appear in.

By the way..."Today" can't be used in VBA

John
 
Mathew,

You've already had 2 responses in the .misc group.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
I'd think

Worksheets("yoursheetname").Range("A1").Value = Date

would be more appropriate than using Now, or perhaps

With Worksheets("yoursheetname").Range("A1")
.NumberFormat = "m/d/yy"
.Value = Date
End With

John Wilson said:
Mathew,

Private Sub CommandButton1_Click()
Worksheets("yoursheetname").Range("A1") = Now
End Sub

You can replace the "Now" with something like:
Format(Now, "m/d/yy")
or whatever format you'd like it to appear in.

By the way..."Today" can't be used in VBA

John
 
MPB said:
Good evening all

I am after some simple code to apply to a CommandButton1_Click(),
where when the button is clicked, today's date is inserted into the active cell.
(Though I do require this date to then be fixed, and not change the following day)

Any help most appreciated.
Thank you
Mathew

type:

Control ; in a cel, jou have a fixed date
 
J.E.

Got into the habit of just using "Now" and just formatting it the way
I want to see it. Old habits are hard to break.
"Date" would be a lot easier if that's all someone needed.

John

J.E. McGimpsey said:
I'd think

Worksheets("yoursheetname").Range("A1").Value = Date

would be more appropriate than using Now, or perhaps

With Worksheets("yoursheetname").Range("A1")
.NumberFormat = "m/d/yy"
.Value = Date
End With
 
Back
Top