ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Toggle Command Button to Show/Hide the Shaded Headers Columns (https://www.excelbanter.com/excel-programming/409717-toggle-command-button-show-hide-shaded-headers-columns.html)

u473

Toggle Command Button to Show/Hide the Shaded Headers Columns
 
How do I code a Toggle Command Button to Show or Hide all Columns
which
headers are shaded ?

Thank you,

Celeste

Mark Ivey[_2_]

Toggle Command Button to Show/Hide the Shaded Headers Columns
 
Not sure where your commandbutton will be located... but here is some code
you can apply to it...

If you embed a commandbutton on the worksheet, the first thing that should
pop up is what macro you want to assign to it.

Here is what I would do:
1. Copy the macro below
2. Open your Excel file
3. Hit ALT + F11 to open the VBE
4. Insert a new module
5. Paste the code (shown below)
6. Go to the worksheet you want this commandbutton on
7. Insert/Embed your command button
8. Use the pop up to assign it to the new macro

Mark Ivey


Sub HideColumnsWithShadedHeaderCells()
Dim myRange As Range

For i = 1 To 256

Set myRange = Cells(1, i)

If myRange.Interior.ColorIndex < xlNone Then
myRange.EntireColumn.Hidden = True
End If
Next

End Sub




All times are GMT +1. The time now is 06:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com