Solved Date and timestamp code needs modified

February 13, 2014 at 08:08:14
Specs: Windows 7
Date and Time Stamp code is as follows
Sub CommandButton1_Click()
Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Now
End Sub
this code when assigned to a button of checkbox will enter a timestamp and date stamp starting at Cell A2 clicking it again puts one in Cell A3 and so on. The problem is, yes I can reference a specific cell but that means 5500+ specific codes and specific buttons. What I want to modify is to make this code reference an activecell so say I am clicked in Cell D22 and then Click date and timestamp button I want the date and timestamp to show in that cell.

Anyone know how to modify this to make that work?


See More: Date and timestamp code needs modified

Report •


#1
February 13, 2014 at 08:42:13
✔ Best Answer
First, please take a moment to click on the blue line at the bottom of this post and read the instructions on how to post VBA code in this forum so that it is easier for us to read.

Sub CommandButton1_Click()
      Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Now
End Sub

Obviously a macro with a single line of code is not that hard to read, but longer macros benefit by having the indents retained when posted.

As for your question, this syntax determines the next empty cell Column A:

Range("A" & Rows.Count).End(xlUp).Offset(1)

If you simply replace that with ActiveCell, the code will put the timestamp in the active cell.

Sub CommandButton1_Click()
      ActiveCell.Value = Now
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

message edited by DerbyDad03


Report •
Related Solutions


Ask Question