Using Named Range in Worksheet Change Event

karabiner8

Board Regular
Joined
Jan 11, 2005
Messages
50
Hi,

I'm developing spreadsheet where the user will enter a path to a network drive in cell B6 of a worksheet named Input. Excel automatically creates a hyperlink after the path is entered. I'd like to use a Worksheet Change event to remove the hyperlink as soon as it's created but instead of entering "$B$6" as the target address I'd like to use the Name I've assigned to the range ("ScrdPath"). This way I don't have to worry about the target cell moving while I'm changing the layout of the worksheet.

This code works:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$6" Then
     Range("$B$6").Hyperlinks.Delete
End If
End Sub

This code does nothing (no errors reported):
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("ScrdPath") Then
     Range("ScrdPath").Hyperlinks.Delete
End If
End Sub

I've checked to make sure that I named cell B6 ScrdPath. Can anyone tell me what I'm doing wrong?

Thanks
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("ScrdPath")) Is Nothing Then
     Target.Hyperlinks.Delete
End If
End Sub
 
Upvote 0
You need to access the Address property of the named range:

Rich (BB code):
If Target.Address = Range("ScrdPath").Address Then
 
Upvote 0
Thank you VoG and Richard Schollar. I took a little bit from both your replies and got this to work:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("ScrdPath").Address Then
     Target.Hyperlinks.Delete
End If
End Sub

Thanks for saving me a ton of grieve.

Karabiner8
 
Upvote 0
Thanks for that post!

I have been searching the internet 4 hours trying to figure that one out. :eek:

The code is working flawlessly for me now.

HUGE THANKS!

Jerry
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,580
Members
449,174
Latest member
chandan4057

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