VBA Modifed Date

Mr Jukebox

New Member
Joined
Sep 25, 2008
Messages
36
What i would like to do is if any cell in C5:H10 is modified i want the date and time to be placed in column B. Currently this is what i have

Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("C5:H105")) Is Nothing Then Exit Sub ' C1:C100 is the price range
Target.Offset(0, -1).Value = Now() ' This will put the current date 6 columns over

End Sub

This works but will put the date and time of the change 1 cell to the left is there a way to get this information directed to only column B?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Intersect(Target, Range("C5:H105")) Is Nothing Then Exit Sub ' C1:C100 is the price range
Range("B" & Target.Row).Value = Now()
End Sub
 
Upvote 0
That works perfectly can you explain why you used this line "If Target.CountLarge > 1 Then Exit Sub"

I changed the original code to this and it seems to work also just curious what the difference is.

Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("C5:H105")) Is Nothing Then Exit Sub
Range("B" & Target.Row).Value = Now() ' This will put the current date in column B

End Sub
 
Upvote 0
Using your code, try changing more than one cell at once & see what happens.
 
Upvote 0
You could also write it this way, which would allow you paste values into multiple cells.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range
Set d = Intersect(Target, Range("C5:H105"))
If d Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each c In d
    Range("B" & c.Row).Value = Now()
Next
Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top