brett1again
New Member
- Joined
- Jun 2, 2022
- Messages
- 10
- Office Version
- 365
- Platform
- MacOS
Hello,
I'm trying to combine 2 worksheet_change codes and I can't seem to get it figured out. I'd really appreciate some help.
Here are the 2 codes separately:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Not Intersect(Target, Range("U:U")) Is Nothing Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
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("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
End Sub
Hope it's not to much to ask but once I get these combined I was also needing to add a code that piggybacks the move row/delete row code above. The code above moves the row from sheets"Tracker" to sheets"completed" when "close" is selected and then deletes it from sheets"tracker". I'd like to be able to move the row back to its original position if it was closed in error by selecting "return" in the same AD column. I've tried to create the code but I'm a definite novice when it comes to VBA and thought I'd ask for some help. Thanks in advance for the help!
I'm trying to combine 2 worksheet_change codes and I can't seem to get it figured out. I'd really appreciate some help.
Here are the 2 codes separately:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Not Intersect(Target, Range("U:U")) Is Nothing Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
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("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
End Sub
Hope it's not to much to ask but once I get these combined I was also needing to add a code that piggybacks the move row/delete row code above. The code above moves the row from sheets"Tracker" to sheets"completed" when "close" is selected and then deletes it from sheets"tracker". I'd like to be able to move the row back to its original position if it was closed in error by selecting "return" in the same AD column. I've tried to create the code but I'm a definite novice when it comes to VBA and thought I'd ask for some help. Thanks in advance for the help!