Solved

Highlighting Cells That Reference External Files

Posted on 2010-11-26
8
290 Views
Last Modified: 2012-05-10
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
Comment
Question by:rav_rav
8 Comments
 
LVL 12

Expert Comment

by:sstampf
ID: 34218020
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
 
LVL 11

Expert Comment

by:Swapnil Nirmal
ID: 34218025
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
 

Author Comment

by:rav_rav
ID: 34218151
Hi Shashank,

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

Thanks,
rav
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 12

Accepted Solution

by:
sstampf earned 500 total points
ID: 34218559
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
 
LVL 13

Expert Comment

by:gbanik
ID: 34218576

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
 

Author Closing Comment

by:rav_rav
ID: 34218678
Great.  Thanks for your help.
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 34220109
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
 

Author Comment

by:rav_rav
ID: 34231542
Thanks for the info brettdj.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question