I have cells in column B,D,F,H,J in a sheet called “Table of Contents” where I want to run through the cells in the entire column to look for a sheet in the workbook with the same name/text string and hyper link to A1. Below is my current code, however it stops if there is a range of empty cells before another set of text. I want this to run through the entire column range I have listed.
Sub CreateHyperLinks()
Dim wsMaster As Worksheet, ws As Worksheet, m, c As Range
Dim wb As Workbook
Set wb = ThisWorkbook
Set wsMaster = wb.Worksheets("Table of Contents")
For Each ws In wb.Worksheets
If ws.Name <> wsMaster.Name And ws.Name <> "Table of Contents" Then
m = Application.Match(ws.Name, wsMaster.Range("B:J"), 0)
Set c = wsMaster.Cells(m, "B:J")
DoLink c, ws.Range("a1")
DoLink ws.Range("a1"), wsMaster.Range("A1"), _
"Back to " & wsMaster.Name
End If
End If
Next ws
End Sub
Sub DoLink(FromCell As Range, ToCell As Range, Optional LinkText As String = "")
FromCell.Worksheet.Hyperlinks.Add Anchor:=FromCell, Address:="", _
SubAddress:="'" & ToCell.Worksheet.Name & "'!" & ToCell.Address(False, False), _
TextToDisplay:=IIf(Len(LinkText) > 0, LinkText, FromCell.Text)
End Sub
1