Hyperlinks in Workbook not playing!!!

Taff

Board Regular
Joined
Mar 31, 2004
Messages
151
Office Version
  1. 365
Platform
  1. Windows
  2. Web
I create an index page, of a large work book, with all the relevant information I need and create hyperlinks for each individual sheet. However when trying to activte the link I get the following message - Reference is not Valid.

The code I am using to create the links is below, this is part of a much larger code.

When I correct the link manually it appears that all are missing ' ' at either end of the title.

Can anybody point me in the correct direction.

Many Thanks

Taff

SheetCount = ActiveWorkbook.Sheets.Count
Sheets("sheet index").Activate
Range("A1").Select
For i = 1 To SheetCount
If Sheets(i).Name <> "Index Sheet" Then
ActiveCell.Offset(i, 0).FormulaR1C1 = Sheets(i).Name
ActiveSheet.Hyperlinks.Add Anchor:=ActiveCell.Offset(i, 0), Address:="", SubAddress:= _
Sheets(i).Name & "!A1"
End If
Next i
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You will get that error message if you have spaces in your sheet names. Try this revision:

Sub myLinks()
SheetCount = ActiveWorkbook.Sheets.Count
Sheets("Index Sheet").Activate
Range("A1").Select
For i = 1 To SheetCount
If Sheets(i).Name <> "Index Sheet" Then
ActiveCell.Offset(i, 0).FormulaR1C1 = Sheets(i).Name
ActiveSheet.Hyperlinks.Add Anchor:=ActiveCell.Offset(i, 0), _
Address:="", SubAddress:= _
"'" & Sheets(i).Name & "'!A1"
End If
Next i
End Sub

Note that you have an inconsistency in your original macro:

Sheets("sheet index").Activate

If Sheets(i).Name <> "Index Sheet" Then

I assume that it should be “Index Sheet” in both spots.

HTH

Mike
 
Upvote 0
Mike,

Thanks, had to tweak slightly for it to work in my complete code, but it done the job!!

Thanks again

Taff
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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