Cannot get 2 worksheet change macros combined?

Ace71425

Board Regular
Joined
Apr 20, 2015
Messages
130
Hello for the life of me I cannot get these 2 worksheet change events combined. Below is the code of me just pasting one after the other in the same sub. They work seperately but the bottom one doesnt work when they're combined. Thank you.

Code:
Private Sub Worksheet_Change(ByVal TARGET As Range)
    Dim A As Range, B As Range, Inte As Range, r As Range, sReason As Variant
    Set A = Range("C:C")
    Set Inte = Intersect(A, TARGET)
    If Inte Is Nothing Then Exit Sub
    Application.EnableEvents = False
        For Each r In Inte
            r.Offset(0, -1).Value = Date
        Next r
    Application.EnableEvents = True
    If TARGET.Cells.Count > 1 Then Exit Sub
     
    Application.ScreenUpdating = False
    
 **THIS IS WHERE SECOND MACRO BEGINS**** 
 If Not Intersect(TARGET, Range("D1:D500")) Is Nothing Then
    sReason = ""
    If TARGET.Value = "MISC" Then
        While sReason = ""
            sReason = Application.InputBox("Reason for MISC?", Type:=2)
            If sReason = False Then
                TARGET.ClearContents
            Else
                TARGET.Offset(0, 14) = sReason
            End If
        Wend
    End If
End If
     
    Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi,

Try it this way.

Code:
Private Sub Worksheet_Change(ByVal TARGET As Range)
    Dim A As Range, B As Range, Inte As Range, r As Range, sReason As Variant
    Set A = Range("C:C")
    Set Inte = Intersect(A, TARGET)
    If Not Inte Is Nothing Then
    Application.EnableEvents = False
        For Each r In Inte
            r.Offset(0, -1).Value = Date
        Next r
    Application.EnableEvents = True
    If TARGET.Cells.Count > 1 Then Exit Sub
     
    Application.ScreenUpdating = False
    End If
 '**THIS IS WHERE SECOND MACRO BEGINS****
 If Not Intersect(TARGET, Range("D1:D500")) Is Nothing Then
    sReason = ""
    If UCase(TARGET.Value) = "MISC" Then
        While sReason = ""
            sReason = Application.InputBox("Reason for MISC?", Type:=2)
            If sReason = False Then
                TARGET.ClearContents
            Else
                TARGET.Offset(0, 14) = sReason
            End If
        Wend
    End If
End If
     
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Hi,

They both work fine for me. You may have disabled events while altering the macro. Paste this snippet of code in and run it


Code:
Sub ss()
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,321
Messages
6,124,239
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top