I have the following code. It lists the sheets names in a sheet called "Index" and then hyperlinks each sheet name back to their respective sheet. However, when I go to click on the hyperlink it tells me that the reference is not valid. Does anyone know why that error would be happening?
Thanks for you help.
Sub IndexSheetNames()
'This will create an index of all the tab names
Dim SheetNames
SheetNames = Sheets.Count
Sheets.Add
ActiveSheet.Name = "Index"
Sheets("Index").Move After:=Sheets(SheetNames + 1)
For i = 1 To SheetNames
Range("A" & i) = Sheets(i).Name
Next i
Call Hyperlink
End Sub
Sub Hyperlink()
Dim cell As Range, ws As Worksheet
With Sheets("Index") 'Sheet with the hyperlink sheet names
On Error Resume Next
For Each cell In .Range("A1", .Range("A" & Rows.Count).End(xlUp)) 'Loop for each used cell in column A
If cell.Value <> "" Then
Set ws = Nothing
Set ws = Sheets(cell.Value)
If Not ws Is Nothing Then
.Hyperlinks.Add anchor:=cell, Address:="", SubAddress:=cell.Value
End If
End If
Next cell
On Error GoTo 0
End With
End Sub
Thanks for you help.
Sub IndexSheetNames()
'This will create an index of all the tab names
Dim SheetNames
SheetNames = Sheets.Count
Sheets.Add
ActiveSheet.Name = "Index"
Sheets("Index").Move After:=Sheets(SheetNames + 1)
For i = 1 To SheetNames
Range("A" & i) = Sheets(i).Name
Next i
Call Hyperlink
End Sub
Sub Hyperlink()
Dim cell As Range, ws As Worksheet
With Sheets("Index") 'Sheet with the hyperlink sheet names
On Error Resume Next
For Each cell In .Range("A1", .Range("A" & Rows.Count).End(xlUp)) 'Loop for each used cell in column A
If cell.Value <> "" Then
Set ws = Nothing
Set ws = Sheets(cell.Value)
If Not ws Is Nothing Then
.Hyperlinks.Add anchor:=cell, Address:="", SubAddress:=cell.Value
End If
End If
Next cell
On Error GoTo 0
End With
End Sub