macro track changes return error #6 overflow / #13 type mismatch

kelvin_9

Active Member
Joined
Mar 6, 2015
Messages
444
Office Version
  1. 2019
hello, i'm a macro beginner and i've got an error #6/#13 on this 2 code, what's wrong with this and how can i amend it?
thank you so much

error #13 type mismatch (select more than 1 cell)
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)Dim sSheetName As String
sSheetName = ActiveSheet.Name
If ActiveSheet.Name <> "TRACK" Then
Application.EnableEvents = False
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = ActiveSheet.Name & " – " & Target.Address(0, 0)
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = oldValue
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = Target.Value
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 3).Value = Environ("username")
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 4).Value = Now
'Sheets("TRACK").Hyperlinks.Add Anchor:=Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 5), Address:="", SubAddress:="‘" & sSheetName & "‘!" & oldAddress, TextToDisplay:=oldAddress


'Sheets("TRACK").Columns("A:D").AutoFit
Application.EnableEvents = True
End If
End Sub


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
oldValue = Target.Value
oldAddress = Target.Address
End Sub

error #6 overflow (slecet the whole sheet)
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)Dim sSheetName As String
sSheetName = ActiveSheet.Name
If ActiveSheet.Name <> "TRACK" Then
Application.EnableEvents = False
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = ActiveSheet.Name & " – " & Target.Address(0, 0)
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = oldValue
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = Target.Value
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 3).Value = Environ("username")
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 4).Value = Now
'Sheets("TRACK").Hyperlinks.Add Anchor:=Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 5), Address:="", SubAddress:="‘" & sSheetName & "‘!" & oldAddress, TextToDisplay:=oldAddress


'Sheets("TRACK").Columns("A:D").AutoFit
Application.EnableEvents = True
End If
End Sub


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Count = 1 Then
oldValue = Target.Value
End If
End Sub
 
You're code is designed for changing/pasting individual cells, not entire sheets.
To prevent the error when pasting an entire sheet use
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim sSheetName As String
[COLOR=#ff0000]If Target.CountLarge > 1 Then Exit Sub[/COLOR]
sSheetName = ActiveSheet.Name
If ActiveSheet.Name <> "TRACK" Then
Application.EnableEvents = False
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = ActiveSheet.Name & " – " & Target.Address(0, 0)
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = Oldvalue
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = Target.Value
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 3).Value = Environ("username")
Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 4).Value = Now
'Sheets("TRACK").Hyperlinks.Add Anchor:=Sheets("TRACK").Range("A" & Rows.Count).End(xlUp).Offset(0, 5), Address:="", SubAddress:="‘" & sSheetName & "‘!" & oldAddress, TextToDisplay:=oldAddress


'Sheets("TRACK").Columns("A:D").AutoFit
Application.EnableEvents = True
End If
End Sub
superb cool, thanks a lot Fluff
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,656
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top