Worksheet Change: Multiple target addresses

hensleyj

New Member
Joined
Apr 2, 2012
Messages
39
I am trying to make the worksheet change, to look at 2 different cells and if they become YES or NO, call a macro.

I am new to worksheet change events, so im not sure how to do this. I can get 1 change to work...i cant get 2 target addresses to work.

Can anyone help?

Its important that the worksheet change event only occurs when G19 or G127 change.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


    If Target.Count > 1 Then Exit Sub
    If Target.Address(0, 0) = "G19" Then
        If Target.Value = "Yes" Then
        Call NoClaimBonus
  
        ElseIf Target.Value = "No" Then
            Worksheets("TD Payment Calculator").Unprotect
            Call NoNoClaimBonus
   End If
   
 If Target.Count > 1 Then Exit Sub   
     If Target.Address(0, 0) = "G127" Then
        If Target.Value = "Yes" Then
        Call NoClaimBonus
       
  
        ElseIf Target.Value = "No" Then
            Worksheets("TD Payment Calculator").Unprotect
            Call NoNoClaimBonus
            
        End If
        Application.EnableEvents = True
    End If
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
What do you want to happen if one cell is a YES and the other is a NO?
 
Upvote 0
Try this:-
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("G19,G127")) Is Nothing Then
    If Target.Value = "Yes" Then Call NoClaimsBonus
    If Target = "No" Then Call NoNoClaimsBonus
End If
End Sub
 
Upvote 0
Thanks, only one thing...

with G19, when Yes, "NOclaimBonus" Macro, when No, "NoNoclaimBonus" macro

With G127, when Yes, "Garnish" Macro, when No, "Garnish" macro

I need to use 4 different macros. 2 for each cell with a yes, and a no macro.

I hope this makes sense?

thanks for your help
 
Upvote 0
Thanks, only one thing...

with G19, when Yes, "NOclaimBonus" Macro, when No, "NoNoclaimBonus" macro

With G127, when Yes, "Garnish" Macro, when No, "Garnish" macro

I need to use 4 different macros. 2 for each cell with a yes, and a no macro.

I hope this makes sense?

thanks for your help
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("G19,G127")) Is Nothing Then
    Select Case Target.Address(0, 0)
    Case "G19"
        If Target.Value = "Yes" Then Call NoClaimsBonus
        If Target.Value = "No" Then Call NoNoClaimsBonus
    Case "G127"
        If Target.Value = "Yes" Then Call Garnish
        If Target.Value = "No" Then Call NoGarnish
    End Select
End If
End Sub
 
Upvote 0
Thanks!

This works for the G19 cell, but doesn't respond to cell change in G127 i'm afraid.
Does G127 change as the result of a manual change in some other cell (i.e. is there a formula in G127)? If yes, you will need to use the precedent cell and not G127 itself.
 
Upvote 0
BINGO!! you nailed it, with a slight mod it now works.. thanks heaps for that.

Thank you both for your help :)
 
Upvote 0
You are welcome - thanks for the reply.

Hi Joe,

I'm trying to use something like this, but the cases work independently but the other one stops. Here is my code, please help.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)




If Not Intersect(Target, Range("C4,C23,C32")) Is Nothing Then
    Select Case Target.Address(0, 0)
    Case "C4"
        If Target.Value = "Ecommerce" Then Call Ecommerce
        If Target.Value = "Non-Commerce" Then Call NonCommerce
        If Target.Value = "Ecommerce & Non-Commerce" Then Call Both
        If Target.Value = "Select Ecommerce/Non-Commerce" Then Call Both
        
    Case "C23"
        If Target.Value = "Select Year" Then Call SelectYear
        If Target.Value = "2020" Then Call Twentytwenty
        If Target.Value = "2021" Then Call TwentyOne
        If Target.Value = "2022" Then Call TwentyTwo
        If Target.Value = "2023" Then Call TwentyThree
        If Target.Value = "2024" Then Call TwentyFour
        If Target.Value = "2025" Then Call TwentyFive
                            
    End Select
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,992
Messages
6,175,829
Members
452,673
Latest member
LaMiaAvy

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