Getting a list of links in a worksheet

Graemea

Board Regular
Joined
Oct 30, 2015
Messages
116
Office Version
  1. 365
Platform
  1. Windows
Hi,

Is it possible to get a list of all links in a particular worksheet to other sheets in the same workbook?

I have a workbook containing many worksheets and with lookups between lots of them so I would like a quick way to see the dependencies between sheets.

Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
The following code will list all links within the active worksheet in a newly created worksheet...

VBA Code:
Option Explicit

Sub ListWorksheetLinks()

    If TypeName(ActiveSheet) <> "Worksheet" Then
        MsgBox "Please make sure that a worksheet is active, and try again!", vbExclamation
        Exit Sub
    End If
    
    On Error Resume Next
    Dim formulaRange As Range
    Set formulaRange = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas)
    If formulaRange Is Nothing Then
        MsgBox "No links found in the active worksheet!", vbExclamation
        Exit Sub
    End If
    On Error GoTo 0
    
    Dim linksArray() As String
    ReDim linksArray(1 To formulaRange.Cells.Count, 1 To 2)
    
    Dim linksCount As Long
    linksCount = 0
    
    Dim formulaCell As Range
    For Each formulaCell In formulaRange
        If InStr(1, formulaCell.Formula, "!") > 0 Then
            linksCount = linksCount + 1
            linksArray(linksCount, 1) = formulaCell.Address
            linksArray(linksCount, 2) = formulaCell.Formula
        End If
    Next formulaCell
    
    If linksCount = 0 Then
        MsgBox "No links found in the active worksheet!", vbExclamation
        Exit Sub
    End If
    
    Dim resultsWorksheet As Worksheet
    Set resultsWorksheet = Worksheets.Add(before:=ActiveSheet)
    
    resultsWorksheet.Range("A1:B1").Value = Array("Location", "Reference")
    
    resultsWorksheet.Range("A2").Resize(UBound(linksArray), UBound(linksArray, 2)).Value = linksArray
    
End Sub

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,214,591
Messages
6,120,431
Members
448,961
Latest member
nzskater

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