We help IT Professionals succeed at work.
Get Started

How to combine 2 Private Sub Worksheet_Change(ByVal Target As Range)

Last Modified: 2018-02-02
These codes don't work when i run them together!!

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim G As Range, H As Range, Inte As Range, r As Range
    Set G = Range("G:G")
    Set Inte = Intersect(G, Target)
    If Inte Is Nothing Then Exit Sub
    Application.EnableEvents = False
        For Each r In Inte
            If r.Offset(0, 1).Value = "" Then
               r.Offset(0, 1).Value = Date
            End If
        Next r
    Application.EnableEvents = True

Exit Sub

Dim rngDest As Range
Set rngDest = Accepted.Range("rngDest")
' Limit the trap area to range of cells in which completed dates are entered as defined above
If Not Intersect(Target, Sheet1.Range("rngTrigger")) Is Nothing Then
' Only trigger if the value entred is a date or is recognizable as a valid date
     If UCase(Target) = "ACCEPTED" Then
'Ensure subsequent deletion of 'moved' row does NOT cause the Change Event to run again and get itself in a loop!
        Application.EnableEvents = False
        rngDest.Insert Shift:=xlDown
' Reset EnableEvents
        Application.EnableEvents = True
    End If
End If

End Sub
Watch Question
Keep everyone healthy; Wear a mask - Social distance - Don't touch your face - Wash your hands for 20 seconds
Most Valuable Expert 2017
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE