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

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
        Target.EntireRow.Select
        Selection.Cut
        rngDest.Insert Shift:=xlDown
        Selection.Delete
' Reset EnableEvents
        Application.EnableEvents = True
    End If
End If

End Sub
Nicole SwisherAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
What are you trying to do with this line?

Set rngDest = Accepted.Range("rngDest")
Nicole SwisherAuthor Commented:
I got the second part of the code to work. The  Set rngdest = Accepted.Range correlates with the worksheet "accepted". I did that for each of the worksheets listed in my document. But what i would like to do is have this code (pasted below) work so that when I add a comment in column g that the date I added the comment to automatically appear in column H.

rivate 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


I have uploaded the file for reference. Thanks again for your help!!

@martinliss
Martin LissOlder than dirtCommented:
There's no file.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Nicole SwisherAuthor Commented:
Nicole SwisherAuthor Commented:
I think i got it to work, does the code look correct to you?
Martin LissOlder than dirtCommented:
It's hard for me to tell but when looking at your code I found that you have the same Worksheet_SelectionChange sub in three places and it should only be in one place and that is in the worksheet code for Sheet1. You should delete the code in Module1 and delete the Sheet11 class module.

On a different subject, see if this modified Worksheet_Change code works for you. It has a couple of advantages. With Select Case, the first case that is true is executed and the the select code is exited as opposed to ElseIf code where all of them are tested even if the first one is true. The second advantage is that I've removed duplicate code.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rngTrigger As Range
Dim rngDest As Range
Dim rngDest2 As Range
Dim rngDest3 As Range
Set rngTrigger = Sheet1.Range("rngTrigger")
Set rngDest = Accepted.Range("rngDest")
Set rngDest2 = Declined.Range("rngDest2")
Set rngDest3 = Inactive.Range("rngDest3")

If Not Intersect(Target, Range("G:G")) Is Nothing And Target.Cells.Count = 1 Then
    Application.EnableEvents = False
    Target.Offset(, 1).Value = Now()
    Application.EnableEvents = True
End If

If Not Intersect(Target, Sheet1.Range("rngTrigger")) Is Nothing Then
    ' Only trigger if the value entered is a number or is recognizable as a number
    Application.EnableEvents = False
    Target.EntireRow.Select
    Selection.Cut
    Select Case UCase(Target)
        Case "ACCEPTED"
            rngDest.Insert Shift:=xlDown
        Case "DECLINED"
            rngDest2.Insert Shift:=xlDown
        Case "INACTIVE"
            rngDest3.Insert Shift:=xlDown
    End Select
    Selection.Delete
    Application.EnableEvents = True
End If

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nicole SwisherAuthor Commented:
Awesome thank you the document runs much faster now!!! The sheet 11 module is for the pop up calendar.
Martin LissOlder than dirtCommented:
The sheet 11 module is for the pop up calendar.
That does not seem to be true.

In any case please don't forget to close this question.
Nicole SwisherAuthor Commented:
I will then remove it. Thanks again for your help!
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.