Join multiple VBA code in to single code / run multi cell checks to show last updated date

Kevw1

New Member
Joined
Dec 6, 2017
Messages
36
Hi I have the following VBA code against sheet 1 and this is working on a single column D4:D100. But now i need to track the date a change to any cell within
4 different
columns independently, I can not get this to work. Can anyone help please? I assume I have joined / linked the code incorrectly. Thanks


Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("D4:D100")) Is Nothing Then Exit Sub
Target.Offset(0, 1) = Now()
Next

If Intersect(Target, Range("G4:G100")) Is Nothing Then Exit Sub
Target.Offset(0, 1) = Now()
Next

If Intersect(Target, Range("J4:J100")) Is Nothing Then Exit Sub
Target.Offset(0, 1) = Now()
Next

If Intersect(Target, Range("N4:N100")) Is Nothing Then Exit Sub
Target.Offset(0, 1) = Now()

End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Maybe this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 If Intersect(Target, Range("D4:D100,G4:G100,J4:J100,N4:N100")) Is Nothing Then Exit Sub
 Target.Offset(0, 1) = Now
End Sub
 
Upvote 0
Hi thanks works great, just wondering if I need it, how would I change the offset value for each column, just thinking if I need to move them all to the right of the sheet to hide from users I could just hide the columns, but would be less likely to be corrupted if I moved to the right of the sheet entirely i guess.
Column D offset by 19,
Column G offset by 20, Column J offset by 21,
Column N offset by 22.
 
Upvote 0
Hi, try this and see if I've understood what you mean.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 If Intersect(Target, Range("D4:D100,G4:G100,J4:J100,N4:N100")) Is Nothing Then Exit Sub
 Target.Offset(0, Evaluate("LOOKUP(" & Target.Column & ",{4,7,10,14},{19,20,21,22})")) = Now
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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