brett1again
New Member
- Joined
- Jun 2, 2022
- Messages
- 10
- Office Version
- 365
- Platform
- MacOS
Hello,
I'm needing some help figuring out a duplication error I'm getting when trying to run essentially the same code on 2 separate sheets within the same workbook. Could someone take a look and let me know what I'm doing wrong or need to change?
"Completed" sheet code:
[/CODE]
"Burial Tracker" sheet code:
I'm needing some help figuring out a duplication error I'm getting when trying to run essentially the same code on 2 separate sheets within the same workbook. Could someone take a look and let me know what I'm doing wrong or need to change?
"Completed" sheet code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Dim xRng As Range
Dim Lastrow As Long
If Target.Count > 1 Then Exit Sub
On Error GoTo Exitsub
Set xRng = Range("U:U").SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0
If Not Application.Intersect(Target, xRng) Is Nothing Then
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
Target.Value = Newvalue
If Oldvalue <> "" Then
If Newvalue <> "" Then
If Oldvalue = Newvalue Or _
InStr(1, Oldvalue, ", " & Newvalue) Or _
InStr(1, Oldvalue, Newvalue & ",") Then
Target.Value = Oldvalue
Else
Target.Value = Oldvalue & ", " & Newvalue
End If
End If
End If
Application.EnableEvents = True
End If
'********Delete record
If Not Intersect(Target, Range("AD:AD")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Dim Lastrow As Long
Lastrow = Sheets("BURIAL TRACKER").Cells(Rows.Count, "AD").End(xlUp).Row + 1
If Target.Value = "RETURN" Then
Rows(Target.Row).Copy Destination:=Sheets("BURIAL TRACKER").Rows(Lastrow)
Rows(Target.Row).Delete
End If
End If
End Sub[CODE=vba]
"Burial Tracker" sheet code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Dim xRng As Range
Dim Lastrow As Long
If Target.Count > 1 Then Exit Sub
On Error GoTo Exitsub
Set xRng = Range("U:U").SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0
If Not Application.Intersect(Target, xRng) Is Nothing Then
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
Target.Value = Newvalue
If Oldvalue <> "" Then
If Newvalue <> "" Then
If Oldvalue = Newvalue Or _
InStr(1, Oldvalue, ", " & Newvalue) Or _
InStr(1, Oldvalue, Newvalue & ",") Then
Target.Value = Oldvalue
Else
Target.Value = Oldvalue & ", " & Newvalue
End If
End If
End If
Application.EnableEvents = True
End If
'********Delete record
If Not Intersect(Target, Range("AD:AD")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Lastrow = Sheets("COMPLETED").Cells(Rows.Count, "AD").End(xlUp).Row + 1
If Target.Value = "CLOSE" Then
Rows(Target.Row).Copy Destination:=Sheets("COMPLETED").Rows(Lastrow)
Rows(Target.Row).Delete
End If
End If
Exitsub:
End Sub