Poderiam me ajudar com unificar esse dois Worksheet_Change(ByVal Target As Range) para mesma planilha:
PRIMEIRO CÓDIGO
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Tratar
Dim campoAlt As String
Dim valorDig As String
Dim linha As Long
linha = Sheets("Registro").Range("A" & Rows.Count).End(xlUp).Row + 1
valorDig = Target.Value
campoAlt = Target.Address
With Sheets("Registro")
.Cells(linha, 1) = Now()
.Cells(linha, 2) = Application.UserName
.Cells(linha, 3) = valorDig
.Cells(linha, 4) = ActiveSheet.Name
.Cells(linha, 5) = campoAlt
End With
Tratar:
Exit Sub
SEGUNDO CÓDIGO:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells(Target.Row + Target.Rows.Count, Target.Item(1, 1).Column).ID = Target.Address
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim nlin As Integer
Dim wsRegistro As Worksheet
Set wsRegistro = ThisWorkbook.Sheets("Registro")
Dim LinhaRegistro As Long
LinhaRegistro = wsRegistro.Cells(wsRegistro.Rows.Count, "A").End(xlUp).Row + 1
nlin = Target.Row
If Target.Item(1, 1).ID <> "" Then
If Target.Rows.Count > 1 Then
wsRegistro.Cells(LinhaRegistro, 1).Value = Now()
wsRegistro.Cells(LinhaRegistro, 2).Value = "Linhas " & nlin & " à " & nlin + Target.Rows.Count & " excluída"
Else
wsRegistro.Cells(LinhaRegistro, 1).Value = Now()
wsRegistro.Cells(LinhaRegistro, 2).Value = "Linha " & nlin & " excluída"
End If
Else
If Target.Rows.Count > 1 Then
wsRegistro.Cells(LinhaRegistro, 1).Value = Now()
wsRegistro.Cells(LinhaRegistro, 2).Value = "Linhas " & nlin & " à " & nlin + Target.Rows.Count & " inserídas"
Else
wsRegistro.Cells(LinhaRegistro, 1).Value = Now()
wsRegistro.Cells(LinhaRegistro, 2).Value = "Linha " & nlin & " inserídas"
End If
End If
Target.Item(1, 1).ID = ""
Cells(Target.Row + Target.Rows.Count, Target.Item(1, 1).Column).ID = Target.Address
End Sub