Automatically Unhide Columns on GoTo

Silverjman

Board Regular
Joined
Mar 19, 2014
Messages
110
I have a sheet1 with sets of grouped (hidden with + box or visible with the - box) columns.

Each group of hidden columns is a Named Range.

On sheet2 I have cells/formulas linking to the grouped/hidden columns/cells on Sheet1.

When I jump (doubleclick or Ctrl-G) from Sheet2 to a specific cell/column on Sheet1 I would like to automatically tigger the appropriate Named Range to Unhide. Right now the code below only unhides the column I've jumped to e.g. D:D when I would like it to unhide the entire Named Range that D:D falls into which is $B:$X.

Code:
Private Sub Worksheet_Activate()


Dim nm As Name, rng As Range
For Each nm In ThisWorkbook.Names
    Set rng = Intersect(ActiveCell, Range(nm.RefersToRange.Address))
    
    If rng.EntireColumn.Hidden = True Then
       rng.EntireColumn.Hidden = False
End If

    If Not rng Is Nothing Then
       
        Exit For
    End If
Next nm

End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Another suggestion from Flevoland (Province in the Netherlands):
Code:
Private Sub Worksheet_Activate()

Dim nm As Name, rng As Range
For Each nm In ThisWorkbook.Names
    Set rng = Intersect(ActiveCell, Range(nm.RefersToRange.Address))
    
     If Not rng Is Nothing Then
       Range(nm.RefersToRange.Address).EntireColumn.Hidden = False
       Exit For
    End If
Next nm

End Sub
 
Upvote 0
Thank you both; I don't think I understand how my code is working you WinteE and when I use your code Marcel it unhides all the grouping on the sheet not just the one that applies to the Named Range of the cell I jumped into.
 
Upvote 0
In Marcels code replace Range(nm.RefersToRange.Address) with Range(rng)
 
Last edited:
Upvote 0
In Marcels code replace Range(nm.RefersToRange.Address) with Range(rng)


Weird now it is giving me a Debug at the line Range(rng).EntireColumn.Hidden = False

Wish I wasn't so simple...
Code:
Dim nm As Name, rng As Range
For Each nm In ThisWorkbook.Names
    Set rng = Intersect(ActiveCell, Range(nm.RefersToRange.Address))
    
     If Not rng Is Not Nothing Then
       Range(rng).EntireColumn.Hidden = False
       Exit For
    End If
Next nm

End Sub
 
Upvote 0
whoops this is Marcels code plus your addition, my LAST paste had one too many NOTs
Code:
Code:
Dim nm As Name, rng As Range
For Each nm In ThisWorkbook.Names
    Set rng = Intersect(ActiveCell, Range(nm.RefersToRange.Address))
    
     If Not rng Is Nothing Then
       Range(rng).EntireColumn.Hidden = False
       Exit For
    End If
Next nm

End Sub


This only unhides one column
Code:
Private Sub Worksheet_Activate()

Dim nm As Name, rng As Range
For Each nm In ThisWorkbook.Names
    Set rng = Intersect(ActiveCell, Range(nm.RefersToRange.Address))
    
     If Not rng Is Nothing Then
       rng.EntireColumn.Hidden = False
       Exit For
    End If
Next nm

End Sub
 
Upvote 0
This is a reaction to post #5. I didn't see the other posts yet.

There must be some misunderstanding.
I tested with a hyperlink on sheet2 linking to a cell on sheet1 that is part of a named range.
When I first hide columns on Sheet1, than follow the hyperlink, only the columns that are part of the named range become visible.
I tried with multiple named ranges, but only the named range to where I'm jumping becomes visible.
Possibly you have overlapping named ranges or so?

Otherwise please provide more details on what's going wrong.
 
Last edited:
Upvote 0
Thanks for all the replies, hmm no I don't have any overlapping ranges. I'm trying to think of another way to describe it or somehow do a Debug.Print
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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