I'm working on a Excel document with a list of items. Because many people are working with this document I need to register by whom, when and where something is changed. All that is realized with VBA in Excel.
When someone change a value in a cell the author name is written in a column, the date and time is written in a column and the cell that has changed gets a thick red border. After checking the change by 2 persons; the datum, time and red border will be removed.
Till here everything is ok and working but when someone wants to insert a new row, delete a complete row or paste a complete row, via the right mouse click functionality there occurs an error.
"Error 13: types do not match".
I don't understand what's going wrong.
Below the Excel VBA code
Br. CLE
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'-----------------------------
' Set selection rulers
'-----------------------------
[GesRij] = Target.Row
[GesKol] = Target.Column
'-----------------------------
' Calculate LastRow & LastColumn
'-----------------------------
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range
Dim Check_01, Check_02
aw_name = ActiveWorkbook.Name
Set sh_name = Worksheets("Blad1")
Set StartCell = Range("A2")
'Find Last Row and Column
LastRow = sh_name.Cells(sh_name.Rows.Count, StartCell.Column).End(xlUp).Row
LastColumn = sh_name.Cells(StartCell.Row, sh_name.Columns.Count).End(xlToLeft).Column
'-----------------------------
'Clear changes
'-----------------------------
sh_name = "Blad1"
With ActiveWorkbook.Sheets(sh_name)
For i = 2 To LastRow
Check_01 = Workbooks(aw_name).Sheets(sh_name).Cells(i, 8).Value
Check_02 = Workbooks(aw_name).Sheets(sh_name).Cells(i, 9).Value
If (Check_01 = "1") And (Check_02 = "1") Then
'Clear data
.Range(Cells(i, 1), Cells(i, 2)).ClearContents
'Clear marker
.Range(Cells(i, 3), Cells(i, 6)).Borders.Color = vbBlack
.Range(Cells(i, 3), Cells(i, 6)).Borders.LineStyle = xlContinuous
.Range(Cells(i, 3), Cells(i, 6)).Borders.Weight = xlThin
Workbooks(aw_name).Sheets(sh_name).Cells(i, 8).Value = ""
Workbooks(aw_name).Sheets(sh_name).Cells(i, 9).Value = ""
End If
Next i
End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------
' Registrate date, time and author of the change
'-----------------------------
Dim Bereik As Range, Controle As Range
Dim DataOld, DataNew
Dim aw_name
Dim sh_name
Set Bereik = ActiveWorkbook.Sheets("Blad1").Range("C:F")
Set Controle = Intersect(Target, Bereik)
With ActiveWorkbook.Sheets(1)
If Not Controle Is Nothing Then
'Write data
.Range("A" & Target.Row) = DateValue(Now)
.Range("B" & Target.Row) = TimeValue(Now)
.Range("G" & Target.Row) = ThisWorkbook.BuiltinDocumentProperties("Last Author")
'Markeer wijziging
DataNew = Target.Value
If DataOld <> DataNew Then
Target.Borders.LineStyle = xlContinuous
Target.Borders.Weight = xlThick
Target.Borders.Color = vbRed
End If
If Target.Cells.Count > 1 Then
Exit Sub
End If
ClOud = Target.Value
End If
End With
End Sub