Worksheet Change Event Using Named Ranges

FracinDean

Board Regular
Joined
Jul 11, 2011
Messages
110
Office Version
  1. 365
Platform
  1. Windows
Can I use named ranges to trigger actions using the Worksheet Change event? I'm having trouble discovering the correct syntax. I tried Target.Range and Target.Name and Target.Address but those didn't work for me. I have several different cells & actions, so something with a SELECT / CASE structure could be really slick. Any ideas?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Maybe something like:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim nam As Name

For Each nam In ActiveWorkbook.Names
If Not Application.Intersect(Target, Range(nam.RefersTo)) Is Nothing Then
'run code
MsgBox "Would you like to play a game?"
Else
'no hit
End If
Next
End Sub


I've never done this so I'm probably missing things like: what happens if the RefersTo is not a range.
 
Upvote 0
Solution
Thanks vconfused. The "Not Application.Intersect Is Nothing" worked for me, I wasn't familiar with that method. Since I didn't want to execute code on ALL the named ranges and I wanted to run different code for different ranges, a slight variation of what you suggested got it done for me:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("NamedRange1")) Is Nothing Then
'code block 1
ElseIf Not Application.Intersect(Target, Range("NamedRangeN")) Is Nothing Then
'code block N
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,699
Members
449,048
Latest member
81jamesacct

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