Vb msgbox with hidden named ranges

Bkruschke

New Member
Joined
Nov 12, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi, I’m new here. I figure I’d get that out of the way right away. I’m also relatively new to the concept of implementing VB into my excel worksheets. I maybe a bit more than a novice but not by much.



So my issue what I’m trying to attempt, is I have a worksheet with multiple drop down choices, and based on those choices I have named ranges that hide whole rows.



What I’m looking to do, is have a way that at any given moment, I code run a piece of code that would tell me exactly what sections, or more precisely what named ranges within my sheet are currently being hidden and display that information in the form of a msgbox.

Like “Range_blah blah is hidden.

the code I found on the web from excel ribbon allows me to detect and list of hidden row numbers. But I would much rather have it tell me what the name of the hidden ranges are.

If anyone can help me out I’d appreciate it.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Welcome to MrExcel

Code below
- loops through all named ranges, and identifies which ones relate to entire rows in active sheet
- identifies those which contain no visible cells
- those ranges which are partially visible are not returned in message box
The code requires that column A is visible
VBA Code:
Sub HiddenRowRanges()
    Dim Nm As Name, Rng As Range, Vis As Range, Ws As Worksheet, Sh As String, c As Long, Msg As String
    Set Ws = ActiveSheet
    Sh = Ws.Name
    c = Ws.Columns.Count
   
    For Each Nm In Ws.Parent.Names
        Set Rng = Nothing
        Set Vis = Nothing
        On Error Resume Next:   Set Rng = Range(Nm.Name):   On Error GoTo 0
        If Not Rng Is Nothing Then
            If Rng.Parent.Name = Sh And Rng.Columns.Count = c Then
                Set Rng = Rng.Resize(, 1)
                On Error Resume Next: Set Vis = Rng.SpecialCells(xlCellTypeVisible): On Error GoTo 0
            End If
        End If
        If Not Vis Is Nothing Then Msg = Msg & vbCr & Nm.Name
       
    Next Nm
    MsgBox Msg, , "Hidden ranges"
End Sub
 
Upvote 0
Sorry, I copied and pasted it into the document and it runs, and returns a blank message, despite the fact that I hid a range. not getting any error or anything from the code.
 
Upvote 0
What is in the NamedRange RefersTo box?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top