If I have 2 code and need them to be both in "sheet1", and they both have the same heading "Private Sub Worksheet_Change(ByVal Target As Range)".
How can I get them to both work together? is there something I need to add between both codes?
How can I get them to both work together? is there something I need to add between both codes?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim f As Range
Dim resp As VbMsgBoxResult
Dim i As Long
If Not Intersect(Target, Range("M:M")) Is Nothing Then
If Target.Count > 1 Then Exit Sub
If Target.Value = "Yes" Then
resp = MsgBox("Is unit returned to service?", _
vbYesNo + vbQuestion)
If resp = vbYes Then
Set f = Range("K:L").Find("RETURNED TO SERVICE", , xlValues, xlPart, , , False)
If Not f Is Nothing Then
i = f.Row + 2
Set f = Range("K:L").Find(Range("H" & Target.Row).Value, , xlValues, xlWhole, , , False)
If Not f Is Nothing Then
MsgBox "This unit already exists in the section."
Exit Sub
End If
Do While True
If Range("K" & i).Value = "" Then
Range("K" & i).Value = Range("H" & Target.Row).Value
Exit Do
End If
i = i + 1
Loop
End If
End If
ElseIf Target.Value = "No" Then
i = 475
resp = MsgBox("Is unit being shopped?", vbYesNo + vbQuestion)
If resp = vbYes Then
Do While True
If Range("A" & i).Value = "" Then
Range("A" & i).Value = Range("H" & Target.Row).Value
Range("C" & i).Value = Range("I" & Target.Row).Value
Range("D" & i).Value = Range("K" & Target.Row).Value
Range("E" & i).Value = "Running Repair"
Exit Do
End If
i = i + 1
Loop
End If
End If
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim f As Range
Dim resp As VbMsgBoxResult
Dim i As Long
If Not Intersect(Target, Range("F:F")) Is Nothing Then
If Target.Count > 1 Then Exit Sub
If Target.Value = "Completed" Then
If Target.Offset(0, -1).Value = "Running Repair" Then
resp = MsgBox("Is unit returned to service?", _
vbYesNo + vbQuestion)
If resp = vbYes Then
Set f = Range("I:J").Find("RETURNED TO SERVICE", , xlValues, xlPart, , , False)
If Not f Is Nothing Then
i = f.Row + 2
Set f = Range("I:J").Find(Range("A" & Target.Row).Value, , xlValues, xlWhole, , , False)
If Not f Is Nothing Then
MsgBox "This unit already exists in the section."
Exit Sub
End If
Do While True
If Range("I" & i).Value = "" Then
Range("I" & i).Value = Range("A" & Target.Row).Value
Exit Do
End If
i = i + 1
Loop
End If
End If
End If
End If
End If
End Sub
Last edited: