Consulting

Results 1 to 7 of 7

Thread: How to highlight cells with dependents in other worksheets?

  1. #1
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    3
    Location

    How to highlight cells with dependents in other worksheets?

    Hi,

    I am looking for a way to highlight all cells (in all tabs) that are referenced by cells in other tabs, i.e. all cells that have dependents in other tabs (dependents on the same tab are easier to trace).

    I am reviewing a lot of models in my job and it would be very helpful if could quickly see which cells are used by other tabs so that I pay more attention to them as they drive other parts of the model. Currently I have to trace dependents cell by cell to check if certain cells are used by other tabs which is very time consuming.

    Thanks a lot for your help, I am sure you will be able to help because I am asking the best of the best

    PS If you have any recommended sources (books, e-courses, free or paid) for someone to start learning VBA to be used for Excel financial models let me know

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    By Rick Rothstein
    Here is some code I have posted in the past, modified for your condition, which will color the cells red. However, note that these cells are only the ones in the UsedRange for the ActiveSheet. So if the used range was A1:F9 and you had a formula somewhere that referenced A1:A100, only A1:A9 will get colored in. It would take what seems like forever to search every cell on the worksheet looking to see if it is a dependent cell or not.
    Sub ColorDependentCellsOnActiveSheetRed()
        Dim ShapeCount As Long, R As Range, DependantCells As Range
        Application.ScreenUpdating = False
        ActiveSheet.ClearArrows
        ShapeCount = ActiveSheet.Shapes.Count
        For Each R In ActiveSheet.UsedRange
            R.ShowDependents
            If ActiveSheet.Shapes.Count > ShapeCount Then
                If DependantCells Is Nothing Then
                    Set DependantCells = R
                Else
                    Set DependantCells = Union(R, DependantCells)
                End If
            End If
            ActiveSheet.ClearArrows
        Next
        DependantCells.Interior.ColorIndex = 3
        Application.ScreenUpdating = True
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    3
    Location
    That's great!

    Is it possible to amend this code to highlight cells with dependents in other sheets only, excluding the active sheet? My intention is to quickly check if there are cells I should keep in mind that are used globally, while reviewing a specific sheet in detail, because otherwise almost all cells will have dependents in the active sheet and all cells will be red.

    Thank you so much!

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Call this from the first sub

    'Based upon
    'https://colinlegg.wordpress.com/2014/01/14/vba-determine-all-precedent-cells-a-nice-example-of-recursion/
    Sub Omitsamesheet()
     
        Dim rngToCheck As Range
        Dim rngPrecedents As Range
        Dim rngPrecedent As Range
        Dim r As Range
        Dim PrecedentCells As Range
        
        For Each r In ActiveSheet.UsedRange
     
        Set rngToCheck = r
     
        On Error Resume Next
        Set rngPrecedents = rngToCheck.Precedents
        On Error GoTo 0
     
        If rngPrecedents Is Nothing Then
            'Do nothing
        Else
            For Each rngPrecedent In rngPrecedents
                If PrecedentCells Is Nothing Then
                    Set PrecedentCells = rngPrecedent
                Else
                    Set PrecedentCells = Union(rngPrecedent, PrecedentCells)
                End If
            Next rngPrecedent
        End If
        Next r
        PrecedentCells.Interior.ColorIndex = xlNone
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    3
    Location
    Almost! This excludes all cells with dependents in the same sheet, even those that have dependents in other sheets and need to be highlighted too. Any solution to that?

    I appreciate your help!

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post a sample workbook?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •