VBA code for Timestamp

G

Guntars

Gentlemen,
I am new to VBA, what I am trying to achieve is, for example when I enter a
text in cell A1 I want VBA script automatically put timestamp in a cell B1
and so on. There will be more text added later in column A, and I always want
the timestamp to appear right next to it, in column B.
I hope somebody will be able to help me, and also explain the steps how it’s
done.

Thank you,
Guntars
 
J

Jacob Skaria

Launch VBE using Alt+F11. From the left treeview double click Sheet1. From
drop down select Worksheet Change and paste the code so as look as below...

Try in Sheet1 ColA

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("$A:$A")) Is Nothing Then
Range("B" & Target.Row) = Now()
End If
End Sub
 
R

Rick Rothstein

Two follow up comments (for Gunter's consideration)...

1) You can also go directly to the code window for Sheet1 (or any sheet for
that matter) by right clicking the sheet's tab and selecting View Code from
the popup menu that appears.

2) There is no need for Gunter to click the drop downs and select Worksheet
and Change as your posted code already has the procedure framework that
doing so produces. All Gunter needs to do is popup the code window (using
either your posted method or #1 above) and copy/paste your posted code into
that code window.
 
G

Guntars

I probably not doing something right.
As Rick Rothstein explained I right clicked on sheet tab -> and selected
View Code -> in VBA pasted the code and saved the script. When I tested in
excel nothing happens. I entered text in A1 but nothing shows up in B1. What
am I doing wrong, or is the timestamp hidden?
 
J

Jacob Skaria

Please set the security level to low/medium in (Tools|Macro|Security).

If this post helps click Yes
 
G

Guntars

Thank you,
It is working great!
Guntars

Jacob Skaria said:
Please set the security level to low/medium in (Tools|Macro|Security).

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top