Dear all,
Hope someone can help me. In fact I do have two problems with my code...
I am absolutely not familiar with VBA and would like to keep the code as simple as possible.
(1)
The code I work with works fine if I change any value in any cell in the worksheet. BUT I would like to set a condition that saves the changes ONLY if I change the value in column G. How can I do that?
(2)
As I said, the changes are saved in the Log-Sheet but it overwrites the former content.
An example:
If I change column G12 in the original worksheet, the Log-Sheet saves the changes in the cells A2-E2.
If I change column G17 in the original worksheet, the Log-Sheet saves the changes in the cells A2-E2. But I would like to save the new changes in a new row (creating a list of changes over the course of the time).
This is the failing code I have so far:
- - -
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim LR As Long
If Sh.Name = "Log" Then Exit Sub
Application.EnableEvents = False
With Sheets("Log")
LR = .Range("A" & Rows.Count).End(xlUp).Row
.Range("A" & LR + 1).Value = Range("F" & Target.Row).Value
.Range("B" & LR + 1).Value = Range("G" & Target.Row).Value
.Range("C" & LR + 1).Value = Range("A" & Target.Row).Value
.Range("D" & LR + 1).Value = Range("B" & Target.Row).Value
.Range("E" & LR + 1).Value = Range("E" & Target.Row).Value
.Range("F" & LR + 1).Value = Now
End With
Application.EnableEvents = True
End Sub
- - -
My code is based on this code (I found in your forum) and it creates a list (just as I want to) but if I apply my changes in the code it does not create a list anymore but overwrites the former content in the cells. Any ideas?
- - -
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim LR As Long
If Sh.Name = "Log" Then Exit Sub
Application.EnableEvents = False
With Sheets("Log")
LR = .Range("A" & Rows.Count).End(xlUp).Row
.Range("A" & LR + 1).Value = Now
.Range("B" & LR + 1).Value = Sh.Name
.Range("C" & LR + 1).Value = Target.Address(False, False)
.Range("D" & LR + 1).Value = Target.Value
End With
Application.EnableEvents = True
End Sub
- - -
Please help!
The desperate Matt81.
Bookmarks