Repeating VB script for other cells in same worksheet

Joined
May 17, 2012
Messages
1
Reaction score
0
I'm a newb here, so thanks in advance for the help and patience.

I'm using the script below to provide the time and date when information is entered in an adjacent cell. Works like a charm. However, I want the script to also work for cells a few columns over, such as Column F, for example, placing the time and date information in the same row the next column over. I don't have a clue how to get this to repeat, or if I need to add a new script, or if so, how to add a new one...

Again, thanks for any and all help....here's the script:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("A2:A10"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 1).ClearContents
Else
With .Offset(0, 1)
.NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub
 
Below is your code with two lines commented. It works for every cell in the worksheet.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Count > 1 Then Exit Sub
[COLOR=green]'If Not Intersect(Range("A2:A10"), .Cells) Is Nothing Then[/COLOR]
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 1).ClearContents
Else
With .Offset(0, 1)
.NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
[COLOR=green]'End If[/COLOR]
End With
End Sub
 
Back
Top