Wednesday, February 15, 2017

vba - How can I keep history of data changes in one excel workbook

A user posted this in a different question:



Here's some code that will watch the range A1:G12 on whatever sheet has the code in it. If r is the row that was changed, then the code
will copy everything from Ar:Gr into a sheet whose code name is
shtLog. (Code name is the name shown in VBA, not the name on the tab
you see in Excel.) This should get you moving in the right direction.


 Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Integer
Dim c As Integer
Dim arr(1 To 1, 1 To 12)
If Not Intersect(Target, Range("A1:G12")) Is Nothing Then
r = Target.Row
For c = 1 To 12
arr(1, c) = Cells(r, c).Value
Next
With shtLog
.Range(.Cells(.UsedRange.Rows.Count + 1, 1), .Cells(.UsedRange.Rows.Count + 1, 12)) = arr
End With
End If
End Sub


However, Although I can see the code I have used in a module and in the VBA Editor I can't see, find, select or run the macro so I have no idea how to get the logger to work.


Would anyone know how to get the code to work so it starts recording in the designated sheet?

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...