Two-level column hiding

scoha

Active Member
Joined
Jun 15, 2005
Messages
428
I have three named ranges of columns - all adjacent to each other (eg A:G, I:Z, AA:BZ)

In each group of columns there will be some columns that are used for lists and will have label data in the first row.

I want to have a macro that toggles between hiding all columns that are empty across all ranges and then three other macros which selectively display only columns that have data in each range.

How do I combine EntireColumns.Hidden=True with "sub" macros where I want to display just those within each range?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Code:
Sub Hid()
if Range("H1").EntireColumns.Hidden = True Then Range("H1").EntireColumns.Hidden = False
 
End Sub
 
Upvote 0
Assuming that your ranges are in fact adjacent, test this in a copy of your workbook.

I have also assumed that the determination of hiding and unhiding depends only on row 1 being blank or not and that the top row of the combined ranges has at least one blank cell.

I have used range names "Range1", "Range2" and "Range3". Change the code to suit your range names.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Hide_Unhide()<br>    <SPAN style="color:#00007F">Dim</SPAN> rUnion <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> lCount <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    <SPAN style="color:#00007F">Set</SPAN> rUnion = Union(Range("Range1"), Range("Range2"), Range("Range3")).Rows(1)<br>    <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br>    lCount = rUnion.SpecialCells(xlCellTypeBlanks).SpecialCells(xlCellTypeVisible).Count<br>    <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0<br>    rUnion.SpecialCells(xlCellTypeBlanks).EntireColumn.Hidden = (lCount > 0)<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

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