Track Cell Changes

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
840
Hello,

So I am looking for the most efficient way using VBA worksheet_change to track cell changes and populate into a column.

So say I have cells A1 and A2, when either of them change I want to populate it into another column, say C and D.

I will have quite a few of these so looking for the most efficient code under this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Many thanks.
 
Yes that is right, although both are copied regardless of which changes, either A1 or A2.

So if A1 changes from Apple to Pear and A2 remains constant, it will still copy them to the next available row in columns C and D.

Make sense?
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
So if A1 Changes or A2 changes the script runs. Changing values in column C and D

Looks like to me you will have duplicates in column C and D

The second you make the change column C and D will change

So even if A2 does not change the value in column D will change

Your sure that is what you want?

So you may have Apple in C1 and C2
 
Upvote 0
Managed to have something that works...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


Dim nR As Long


nR = WorksheetFunction.Max(2, Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Row + 1)


If Not Intersect(Target, Range("A1:A2")) Is Nothing Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Range("A1").Copy Destination:=Sheets("Sheet1").Range("C" & nR)
Range("A2").Copy Destination:=Sheets("Sheet1").Range("D" & nR)


End If


End Sub
 
Upvote 0
Managed to have something that works...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


Dim nR As Long


nR = WorksheetFunction.Max(2, Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Row + 1)


If Not Intersect(Target, Range("A1:A2")) Is Nothing Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Range("A1").Copy Destination:=Sheets("Sheet1").Range("C" & nR)
Range("A2").Copy Destination:=Sheets("Sheet1").Range("D" & nR)


End If


End Sub

Had to go to bed. But glad to see you found a answer some other place.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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