Track changes on a Worksheet in Excel with VBA

Peteor

Board Regular
Joined
Mar 16, 2018
Messages
152
I am currently using the following:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("O:T")) Is Nothing Or Range("W2") = vbNullString Then GoTo Skip
If Range("W2") <= Range("W1") Then
If Not Intersect(Target, Range("A:U")) Is Nothing Then
Call Automatic_Highlights(Target)
End If
End If

End Sub


Which Calls the following when a change is made:

Sub Automatic_Highlights(Rng As Range)


Rng.Interior.ColorIndex = 26
Intersect(Rng.EntireRow, Range("U:U")).Interior.ColorIndex = 26


End Sub



It works, and is currently in use. However..... There are annoying nuances. EG.... When a cell is copied, and a user presses enter, it calls Automatic_Highlights. EG.... When you actually enter the cell as if to type, but do not change the value, when you click off, it calls Automatic_Highlights.

I think a solution would be to somehow track the cell value before and after the event, and highlight if they are not the same. Honestly, I have written MANY macros, but am unsure how this one is operating regarding the intersect method. Would anyone have any suggestions?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I am working a solution but am having an issue with the Target.Value method. See the below:

Dim oldValue As Variant
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
oldValue = Target.Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("O:T")) Is Nothing Or Range("W2") = vbNullString Then GoTo Skip
If Range("W2") <= Range("W1") Then
If Not Intersect(Target, Range("A:U")) Is Nothing Then
If Target.Value <> oldValue Then
Call Automatic_Highlights(Target)
Else
End If
End If
End If


Skip:
If Not Intersect(Target, Range("O:T")) Is Nothing Then
Call Date_Highlights(Target)
End If




End Sub

This works for single cell changes, but has a mismatch error when copying/pasting a multiple cell selection. I see the .Value method is only for single cells. How would I accomplish the same, but account for a multiple cell selection? Is my only option to consider using dynamic arrays?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
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