worksheet change

gbell3587

Board Regular
Joined
Jan 30, 2011
Messages
117
Hi

I know about the worksheet events but i have a whole range of cells that this would apply to and im not sure how i would do it.

Basically i want to date changes so if the user edits the data in a1, i want b1 to date the last time the cell a1 was changed. I have data in the whole of column a adn would also like the whole of column b to record any time the given row in column a changes.

Can anyone help?

as another example, i change cell a1 now - i want b1 to store todays date.

if i change cell a5000 on the 1/5/2011, i want this date to be displayed in cell b5000.

Thanks
Graham
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Look at the Intersect Method..

Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range, c As Range
Set MyRange = Intersect(Target, Range("A:A"))
If MyRange Is Nothing Then Exit Sub
For Each c In MyRange
    c.Offset(0, 1).Value = Date
Next c
End Sub
 
Upvote 0
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
    Application.EnableEvents = False
    Target.Offset(, 1).Value = Now
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Look at the Intersect Method..

Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range, c As Range
Set MyRange = Intersect(Target, Range("A:A"))
If MyRange Is Nothing Then Exit Sub
For Each c In MyRange
    c.Offset(0, 1).Value = Date
Next c
End Sub

Thanks alot, much appreciated - you guys on this forum are unreal at helping quickly!

Ive never seen the intersect method before - i'll have to look into it. Just 1 more question, is this a static date? It isnt like the =now() function?
 
Upvote 0
At the time the code runs, Date is whatever today's current date is.

Then, the date that was put in the cell remains static After that point.
 
Upvote 0
@VoG, That Application.EnableEvents trick is nice too. I've been burned by large paste/format operations into sheets with a Worksheet_change event defined. Are there other change events, for a range perhaps, or do you have to resort to a data entry box if you need an event and can't tolerate a Worksheet_change?
 
Upvote 0
If I understand your question you can use the Intersect method as in jonmo1's code above.
 
Upvote 0
Not really - problem was the Worksheet_change reacting a bazillion times to things I didn't care about. Testing and exiting the macro still cost time. I want to avoid reacting at all to changes in/outside a defined area. I'll disable the event when I know a big change is coming but if a user pastes a few thousand cells...
 
Upvote 0
I think you'll need to be more specific. Better still, start your own thread as yours seems to be a different question.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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