Excel

Highlight all cells in the active sheet that have formula links to other sheets in this workbook

Ease of Use

Easy

Version tested with

2003 

Submitted by:

brettdj

Description:

This code highlights all formula cells in the active sheet that have references to cells in other sheet with a blue interior 

Discussion:

You are auditing an external spreadsheet and you want a quick visual check for cells that have formulas sourced to other worksheets 

Code:

instructions for use

			

Option Explicit Sub FormatOtherSheetLinks() Dim TestRange As Range, C As Range, MyRange As Range Dim FirstAddress As String, SheetString As String Dim wsh As Worksheet On Error Resume Next 'look at formulas only. There may be no formulas in the sheet Set TestRange = Cells.SpecialCells(xlCellTypeFormulas) On Error GoTo 0 If Not TestRange Is Nothing Then For Each wsh In ActiveWorkbook.Worksheets SheetString = wsh.Name & "*!" 'deal with those messy quotes SheetString = Replace(SheetString, "'", "''") With TestRange 'look in formulas for a sheet name match Set C = .Find(SheetString, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False) If Not C Is Nothing Then FirstAddress = C.Address If MyRange Is Nothing Then Set MyRange = C Do Set C = .FindNext(C) If Not MyRange Is Nothing Then Set MyRange = Union(MyRange, C) Loop Until C.Address = FirstAddress End If End With Next 'Colour all linked cells with a blue interior If Not MyRange Is Nothing Then MyRange.Interior.Color = vbBlue End If Set TestRange = Nothing Set MyRange = Nothing End Sub

How to use:

  1. Copy the code above.
  2. Open your workbook.
  3. Hit Alt+F11 to open the Visual Basic Editor (VBE).
  4. From the menu, choose Insert-Module.
  5. Paste the code into the code window at right.
  6. Close the VBE, and save the file if desired.
 

Test the code:

  1. Run the macro by going to Tools-Macro-Macros and double-click FormatOtherSheetLinks.
 

Sample File:

FormatSheetLink (KB9).zip 10.02KB 

Approved by mdmackillop


This entry has been viewed 227 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express