Toggle Command Button to Show/Hide the Shaded Headers Columns

U

u473

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

Thank you,

Celeste
 
M

Mark Ivey

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top