SuperWamJarice
New Member
- Joined
- Jan 10, 2018
- Messages
- 9
Good afternoon all,
I am working on a pretty big workbook for which a logbook is automatically filled whenever a cell content is changed in any worksheet. It works quite well but I have an issue when the content of multiple selected cells is deleted. A run-time error '13' type mismatch appears. I understand why it happens, as it cannot enter the content of multiple cell into one cell of the logbook, and I found a way to stop this error from appearing, but what I would like to do is
- either to add a line in the logbook giving less details but showing that something happened in the range,
- or (and that would be the best) add 1 line per cell of the range for which content has been deleted, in the logbook
here is the code I made:
I am a beginner with VBA, so my apologize if that code looks ugly.
If I just put :
instead of the whole:
my macro doesn't crash but I don't get the record of the changes made.
Could anyone give me a hint to solve that problem?
Thank you very much in advance,
Seb</vide></vide>
I am working on a pretty big workbook for which a logbook is automatically filled whenever a cell content is changed in any worksheet. It works quite well but I have an issue when the content of multiple selected cells is deleted. A run-time error '13' type mismatch appears. I understand why it happens, as it cannot enter the content of multiple cell into one cell of the logbook, and I found a way to stop this error from appearing, but what I would like to do is
- either to add a line in the logbook giving less details but showing that something happened in the range,
- or (and that would be the best) add 1 line per cell of the range for which content has been deleted, in the logbook
here is the code I made:
Code:
Dim OldVal As Variant
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
OldVal = Target.Value
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Sheets("LogDetails").UnProtect
If activesheet.Name <> "LogDetails" And activesheet.Name <> "Test" And activesheet.Name <> "Front Page" And activesheet.Name <> "Front Sheet" Then
Application.EnableEvents = False
Application.ScreenUpdating = False
If Target.Count > 1 Then 'There is my attempt to log info in case content of multiple cells have been removed
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = activesheet.Name
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 8).Value = Application.UserName
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 9).Value = Date
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 10).Value = Time
Exit Sub
Else
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = activesheet.Name
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = Target.Address(0, 0)
If OldVal = "" Then
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 6).Value = "<vide>"
Else
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 6).Value = OldVal
End If
If Target.Value = "" Then
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 7).Value = "<vide>"
Else
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 7).Value = Target.Value
End If
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 8).Value = Application.UserName
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 9).Value = Date
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 10).Value = Time
Application.EnableEvents = True
End If
End If
Sheets("LogDetails").Protect
Application.ScreenUpdating = True
End Sub
I am a beginner with VBA, so my apologize if that code looks ugly.
If I just put :
Code:
If Target.Count > 1 Then
Exit Sub
Code:
If Target.Count > 1 Then 'There is my attempt to log info in case content of multiple cells have been removed
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = activesheet.Name
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 8).Value = Application.UserName
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 9).Value = Date
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 10).Value = Time
Exit Sub
Else
Could anyone give me a hint to solve that problem?
Thank you very much in advance,
Seb</vide></vide>