running a macro after updating a cell

G

Guest

Hello,

Wanted to know if it is possible in Excel to run a macro after updating a
cell..

For example, I wanted excel to "date stamp" cell B1 (using a macro) after
cell A1 has been updated.

Is that possible...thanx
 
G

Guest

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Range("B1").Value = Date
Application.EnableEvents = True
End Sub

This is worksheet code it goes in the worksheet code area, NOT a standard
module.
 
G

Guest

Thanks..that works great..

Another follow on question would be: Could I be done to a whole column...so
that every time you change an entry on each row, it updates the date in the
column besides it.

thanks
 
G

Guest

Yes. We change two lines of code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, 1).Value = Date
Application.EnableEvents = True
End Sub
 
G

Guest

again works great..

another follow on question :)

At present I've got it running with F:F being updated and a date being
inserted into G:G. Could I also have it doing the same thing on the same
sheet for G:G to H:H, I:I to J:J etc..

I tried to copy the code and edit it to give each module uniqueness but that
didn't work...
 
D

dan dungan

How did you edit it?

again works great..

another follow on question :)

At present I've got it running with F:F being updated and a date being
inserted into G:G. Could I also have it doing the same thing on the same
sheet for G:G to H:H, I:I to J:J etc..

I tried to copy the code and edit it to give each module uniqueness but that
didn't work...
 
G

Guest

I added created another couple SUBS by using the text and editing the column
value. e.g.

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("F:F")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, 1).Value = Date
Application.EnableEvents = True
End Sub

Private Sub Worksheet_Change2 (ByVal Target As Range)
If Intersect(Target, Range("H:H")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, 1).Value = Date
Application.EnableEvents = True
End Sub
 
D

dan dungan

I'm stumped.

I added created another couple SUBS by using the text and editing the column
value. e.g.

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("F:F")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, 1).Value = Date
Application.EnableEvents = True
End Sub

Private Sub Worksheet_Change2 (ByVal Target As Range)
If Intersect(Target, Range("H:H")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, 1).Value = Date
Application.EnableEvents = True
End Sub
 

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