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
 
Silverjman
You have probably different cells on Sheet 2 with a Range-name as a value.
Are tese cells stored in a table ?
 
Upvote 0
Copy this to the VBA part of Sheet2 :


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    Worksheets("Sheet1").Range("A1:D1").EntireColumn.Hidden = True 'hide all columns on Sheet1 here
    
    If Not Intersect(Target, Range("A1:A10")) Is Nothing Then 'change the range to were the cells with names are
        For Each nm In ThisWorkbook.Names
            If nm = Target.Value Then
                Range(nm).EntireColumn.Hidden = False
            End If
        Next nm
    End If
    
End Sub
 
Upvote 0

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