Trigger Macro from Named Range Change

TTom

Well-known Member
Joined
Jan 19, 2005
Messages
518
I want to trigger a macro to run when my named cell range changes.
I have a cell named as range: rng_trigger

In the 'In Worksheet_Change Module'
on first line of code shown below (after Dim statement):

If I use for code:
Set myTriggerCell = Range("rng_trigger")
then:
myTriggerCell = the row# of the cell named "rng_trigger", not the address

If I use for code:
Set myTriggerCell = Range("rng_trigger").Address
then:
it sees the named range as an error and hangs the macro...

Any suggestions?
<code>
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myTriggerCell As Range

Set myTriggerCell = Range("rng_trigger").Address
If Not Application.Intersect(myTriggerCell, Target) Is Nothing Then
Call myMacro
Else:
'Do Nothing
End If
End Sub
</code>
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
As written, myTriggerCell is a range, while Range("rng_trigger").Address is a string, hence the mismatch error.

Try this
Code:
If Not Application.Intersect(Range("rng_trigger"), Target) Is Nothing Then
    Call the macro
End If
 
Upvote 0
Using code:
If Not Application.Intersect(Range("rng_trigger"), Target) Is Nothing Then

it sees it as Nothing and skips to Else:

To be clear, Range("rng_trigger") is not the active cell,
another change in the worksheet causes Range("rng_trigger") to change value,
only when the value changes in the named range should it trigger macro to run.
 
Upvote 0
I'm trying to get this clear. Is this a clear picture of your situation:

You have a named range, rng_trigger. (This is a one cell range?)

You have a macro(?) that sets the value in that range. Or does rng_trigger contain formula(s)?

When the value of rng_trigger changes you want MyMacro to run.

Is that the situation?

If the rng_trigger values are set by macro, a Change event like we have been working with should do the job.

If the rng_trigger value is set by formula, that will not trigger a Change event, the code will need to be modified as
Code:
[code]If Not Application.Intersect(Range("rng_trigger").Precedents, Target) Is Nothing Then
    Call myMacro
End If

If the value in rng_trigger is changed in a more complicated way, (eg a combination of either user entering into the cell or a macro) different approaches might be needed.
 
Upvote 0
Still having some problems, but yes:

1. named range is ale cell
2. named range changes value based on formula in cell
3. changes elsewhere in worksheet combine with formula 'may' change the value
4. when value change occurs macro needs triggered

I did try your code but it now references the value of the cell above it
That cell is one referenced by the formula in the named cell

I was able to figure out another way to make this work in a different manner
In the interest of time I will use the working solution for now and revisit your
recommendations later to see what I can learn...

Thank you.
Tom
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,803
Members
449,468
Latest member
AGreen17

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