Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

Highlighting Cells That Reference External Files

Hi There Experts,

Is there a simple way (including a macro possibly) that I can highlight all the cells in an Excel workbook that have a formula reference to an external file?

Thanks,
rav
0
rav_rav
Asked:
rav_rav
1 Solution
 
sstampfCommented:
You can try this code. Just select the range where you want to test for external links and run the macro. You can also assign a shortcut key to this code.

Thanks
Shashank
Sub sFormat()
Dim rng As Range
For Each rng In Selection
If InStr(2, rng.Formula, "[") Then
rng.Interior.Color = vbBlue
End If
Next rng
End Sub

Open in new window

0
 
Swapnil NirmalCommented:
First paste this function by creating module in VBA (press alt+F11, in project viewer right click on the desired file or personal.xls if you want it global
 
Function IsExternalFormula(rCell As Range) As Boolean
If Not rCell.HasFormula Then Exit Function

IsExternalFormula = InStr(1, rCell.Formula, "[") > 0
End Function

Open in new window


in conditional formatting use the following formula:

=IsExternalFormula(A1)
0
 
rav_ravAuthor Commented:
Hi Shashank,

Thanks for the quick response.  How would i neeed to modify the code to search the entire workbook?

Thanks,
rav
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sstampfCommented:
Try this code:
Sub sFormat()
Dim rng As Range, rng1 As Range
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Sheets
Set rng1 = sht.UsedRange
    For Each rng In rng1
        If InStr(2, rng.Formula, "[") Then rng.Interior.Color = vbBlue
    Next rng
Next sht
End Sub

Open in new window

0
 
gbanikCommented:

Option Explicit

Public Sub HighlightExternalLinks()
Dim oRange As Range, oFindRange As Range, bFindFlag As Boolean
'On Error Resume Next
Do While Err.Number = 0
    If Not bFindFlag Then
        Set oFindRange = ActiveSheet.Cells.Find(What:="[", After:=Cells(1), LookIn:=xlFormulas, LookAt:= _
            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
            , SearchFormat:=False)
        bFindFlag = True
    Else
        Set oFindRange = ActiveSheet.Cells.FindNext(After:=oFindRange)
    End If
    If Err.Number <> 0 Then
        Err.Clear
        Exit Do
    End If
    If Not oFindRange Is Nothing Then
        If Not oRange Is Nothing Then
            If Not Intersect(oRange, oFindRange) Is Nothing Then Exit Do
        End If
        If oRange Is Nothing Then Set oRange = oFindRange Else Set oRange = Union(oRange, oFindRange)
    Else
        Exit Do
    End If
Loop
If Not oRange Is Nothing Then
    oRange.Interior.ColorIndex = 22
    oRange.Activate
End If
End Sub

Open in new window

0
 
rav_ravAuthor Commented:
Great.  Thanks for your help.
0
 
Dave BrettCommented:
While this question is closed my Mappit! does this amongst other thingss, http://www.experts-exchange.com/A_2613.html

And I note that links should be backtested against Linksources to test they are valid. Finding "[" alone may lead to false link identifictaion


Cheers

Dave
0
 
rav_ravAuthor Commented:
Thanks for the info brettdj.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now