View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mark Ivey[_2_] Mark Ivey[_2_] is offline
external usenet poster
 
Posts: 171
Default 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