Solved

Highlighting Cells That Reference External Files

Posted on 2010-11-26
8
274 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

863 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now