Avatar of Nicole Swisher
Nicole Swisher
 asked on

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
Microsoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon
Martin Liss

What are you trying to do with this line?

Set rngDest = Accepted.Range("rngDest")
Nicole Swisher

ASKER
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 Liss

There's no file.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Nicole Swisher

ASKER
Nicole Swisher

ASKER
I think i got it to work, does the code look correct to you?
ASKER CERTIFIED SOLUTION
Martin Liss

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Nicole Swisher

ASKER
Awesome thank you the document runs much faster now!!! The sheet 11 module is for the pop up calendar.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Martin Liss

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 Swisher

ASKER
I will then remove it. Thanks again for your help!
Martin Liss

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
Your help has saved me hundreds of hours of internet surfing.
fblack61