I "found" this vba code to log changes. It works fine if 1 cell is changed, but if several cells are changed simultaneous an error occurs.
What must i edit to make it work?
Private Sub Worksheet_Change(ByVal Target As Range)[/FONT] If target.row > 203 and target.row < 284 and target.column > 4 and target.column < 394 then
[FONT='Verdana','sans-serif']
If Target.Value <> PreviousValue Then
Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
Application.UserName & " verandert cel " & Target.Address _
& " in werkblad ' " & Me.Name & " ' van " & " ' " & PreviousValue & " ' " & "naar " & " ' " & Target.Value & " ' " & " op tijdstip " & Time & " en datum " & Date
End If[/FONT] End if
[FONT='Verdana','sans-serif']
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PreviousValue = Target.Value
End Sub[/FONT]
[/VBA]
In the meantime i understand that it isn't easy to get the result using this code. I found this new code. the problem with this code is that the cell validation results in an error the first time a valid value is entered. If the pulldown menu is used the value will be accepted the next time. Only problem is is that there are 367 valid values.
Anyone an idea?
[VBA]
Dim OldVals As New Dictionary
Private Sub Worksheet_Activate()
Dim cell As Range
For Each cell In Range("E204:OC283")
OldVals(cell.Address) = cell.Value
Next
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
tekst = ""
naam = Application.UserName
For Each cell In Target
If Target.Row > 203 And Target.Row < 284 And Target.Column > 4 And Target.Column < 394 Then
nw = cell.Value
ad = cell.Address
blad = Me.Name
ow = ""
If OldVals.Exists(cell.Address) Then
ow = OldVals(cell.Address)
End If
tekst = tekst & "naam: " & naam & " " & "werkblad: " & blad & " " & "cell: " & " " & ad & "datum en tijd: " & " " & Now & " " & "oude waarde: " & " " & ow & " " & "nieuwe waarde: " & nw & vbLf
End If
OldVals(cell.Address) = cell.Value
Next
Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = tekst
End Sub
No need to delete posts. It's just polite to let each of the boards know there's a cross-post out there. With most people giving of their free time to answer questions, they will be irritated if you're receiving help from others on things they're working with you on. Some solutions take quite a few hours to complete.