Hello,
I am relatively new to VBA and macros and would like to track changes in values of a certain column of a worksheet. I have the values in column F of Sheet 4 (which updates based on values in another sheet through a formula), and I want it to copy to the next available column to the right of it (column G then H etc etc) if the new value of the cell is different from the old value. Right now the code I have below does the copying part great, but it's doing it for all the cells regardless of if the value has changed or not. If I get rid of the for-loop and just have it work on a single row it does exactly what I want. But how do I make this apply to every row? I'm thinking all I have to do is assign a new variable to each row, but I need to learn how to go about doing that quickly. I have a hunch that "PrevVal_i" doesn't really work, so what should I use instead?
In the "This Workbook" page:
Private Sub Workbook_Open()
Dim i As Integer
For i = 2 To 1000
PrevVal_i = Sheet4.Range("F" & i).Value
Next i
End Sub
In the "Sheet4" code page:
Private Sub Worksheet_Calculate()
Application.ScreenUpdating = False
Dim i As Integer
For i = 2 To 1000
If Cells(i, "F").Value <> PrevVal_i Then
Cells(i, Columns.Count).End(xlToLeft).Offset(0, 1) = Range("F" & i)
PrevVal_i = Range("F" & i)
End If
Next i
Application.ScreenUpdating = True
End Sub
Thanks!
Bookmarks