Space in Sheet Title causing Reference Not Valid for Hyperlink

lakomitten11

New Member
Joined
Jun 21, 2017
Messages
7
The purpose of this code is to create a hyperlink to another sheet based off of the 'HyperlinkName' variable which is the last value in the equipment list. A new sheet has already been created with the exact same name as the 'HyperlinkName' variable. The code is creating the hyperlink properly, however when there is a space in the equipment name I will receive a Reference Not Valid error, then the sheet will open.

Code:
[/COLOR]Dim R As Range
    Set R = Cells(Rows.Count, 2).End(xlUp) 'last cell in Column B with data
    If Len(R.Value) > 0 Then Set R = R.Offset(1)
    R.Value = Range("j3").Value




       HyperlinkName = Sheet4.Range("j3").Value




    Sheets("Equipment List").Hyperlinks.Add Anchor:=R, Address:="", SubAddress:= _
    HyperlinkName & "!A1", TextToDisplay:=HyperlinkName
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,535
Office Version
  1. 365
Platform
  1. Windows
Hi, try like this (additions in red):

Rich (BB code):
    Sheets("Equipment List").Hyperlinks.Add Anchor:=R, Address:="", SubAddress:= _ 
   "'" & HyperlinkName & "'!A1", TextToDisplay:=HyperlinkName
 
Last edited:

lakomitten11

New Member
Joined
Jun 21, 2017
Messages
7
Hi, try like this (additions in red):

Rich (BB code):
    Sheets("Equipment List").Hyperlinks.Add Anchor:=R, Address:="", SubAddress:= _ 
   "'" & HyperlinkName & "'!A1", TextToDisplay:=HyperlinkName


That works! Thank you!
 

Forum statistics

Threads
1,136,778
Messages
5,677,678
Members
419,711
Latest member
dacrmcvega0

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
Top