Unfortunately, Excel does not have a built-in command to highlight all cells linking to other worksheets. That means if you are working late at night on the Sunday-Monday morning of Labor Day weekend and need to color all other-sheet links to green in a spreadsheet with thousands of rows mixing numbers, formulas and other-sheet links, YOU ARE FUCKED. Until now.
With the help of my some times enemy and other times friend visual basic, you can do what F5 does, but to select formulas with links to other sheets. Remember, I am not a VBA expert, but I know how to use Google and combine other people's VBA code. Here is what to do:
- ALT + F11 to open up Microsoft Visual Basic within Excel
- ALT, I, M to insert a new module
- Within the module code editing window, paste in: 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
Set TestRange = Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0
If Not TestRange Is Nothing Then
For Each wsh In ActiveWorkbook.Worksheets
SheetString = wsh.Name & "*!"
SheetString = Replace(SheetString, "'", "''")
With TestRange
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
If Not MyRange Is Nothing Then MyRange.Select
End If
Set TestRange = Nothing
Set MyRange = Nothing
End Sub - F5, ALT + R to run the module on each desired sheet
So how did this work? Imagine that a human was doing this exercise. He could use CTRL + F to find each cell containing links to other sheets by searching for "!" within each formula. He could then select each cell that contained "!" cumulatively (using either the keyboard and SHIFT + F8 or the mouse and CTRL). Excel does all of that almost instantaneously. The only problem would be if you write footnotes like, "Assumes leverage of 3.5x!!!!" because that's getting highlighted too. Anyway, imagine the spreadsheet is huge and contains a mix of constants and other formulae. That could have been a 15-minute exercise, but will now take 2 seconds!
Speaking of taking 2 seconds, I decided to write this post while thinking of ways to satisfy Mrs. F-One. Happy Labor Day Weekend.
-F-One