Highlight All Named Ranges Part 1

April 1, 2010 by datapig Leave a reply »

If you spend your time auditing other people's worksheets, you'll know that Excel users love their named ranges. I've run across some spreadsheets where 50 or more individual cells are given individual names. This makes auditing a spreadsheet an extremely muddy experience.

It sometimes helps to know where the named ranges are.

.

Here is a macro I use to highlight all the named ranges in a workbook yellow.

Just copy and paste this code in a new Standard Module. Once you have it in, you can fire this macro to turn all the cells that belong to a named range Yellow.

Visual Basic:
  1. Sub HighlightRanges()
  2. Dim RangeName As Name
  3. Dim HighlightRange As Range
  4.  
  5. On Error Resume Next
  6. For Each RangeName In ActiveWorkbook.Names
  7. Set HighlightRange = RangeName.RefersToRange
  8. HighlightRange.Interior.ColorIndex = 36
  9. Next RangeName
  10.  
  11. End Sub

.

As a bonus, this tip also gives you a visual indication of the level of anal retentiveness your co-workers achieve.

Next week, I'll give you a way to indicate to which Named range each highlighted cell belongs.

RELATED STUFF

  1. Choosing Quarters in Excel
  2. Creating Subtotals on Many Columns
  3. Protect Worksheet Structure with Array Formulas
  4. Using the Switch Function in Excel
  5. Protecting VLOOKUPS from Expanding Data
  6. Copying VLOOKUPs Across Multiple Columns
  7. Flipping a Range Upside Down
  8. Excel Defunct Defaults
  9. Why FIND when you can SEARCH
  10. Getting Data from Previous Sheet
Advertisement

9 Responses

  1. Daniel Ferry says:

    Good suggestion

    But since "Named Ranges" can be defined as constants or formulas that do not result in a range on any worksheet (for example, =c5+d5, and in infinite number of others), the subroutine needs a:

    On Error Resume Next

    ...to prevent it from crashing.

    Regards,

    Daniel Ferry
    excelhero.com/blog

  2. datapig says:

    Daniel: Very good point! I added the error catch.

  3. AlexJ says:

    What about putting the hilites back to normal (whatever was there before you colored them)?
    I have a similar routine that hilites locked cells which uses select instead of color index.

  4. datapig says:

    Alexj: If you don't want to color, but just select the named ranges, you can use this:

    Visual Basic:
    1. Sub HighlightRanges()
    2. Dim RangeName As Name
    3. Dim HighlightRange As Range
    4.  
    5. On Error Resume Next
    6. For Each RangeName In ActiveWorkbook.Names
    7.     If HighlightRange Is Nothing Then
    8.         Set HighlightRange = RangeName.RefersToRange
    9.     Else
    10.         Set HighlightRange = Union(HighlightRange, RangeName.RefersToRange)
    11.     End If
    12. Next RangeName
    13.  
    14. HighlightRange.Select
    15. End Sub

  5. gary says:

    why not just use this:
    Range(RangeName).Interior.ColorIndex = 36

  6. sam says:

    The real Name Manager has this functionality already...

  7. Bob Phillips says:

    Same, you beat me to it, and you used my phrasing :)

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>