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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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