View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Need a macro to hide certain columns

Maybe you can modify this macro to do what you want:

Option Explicit
Sub testme()

Dim iCol As Long

With Worksheets("sheet1")
For iCol = 1 To 30
If .Cells(1, iCol).Font.ColorIndex = 6 _
And .Cells(1, iCol).Interior.ColorIndex = 35 Then
.Columns(iCol).Hidden = True
Else
.Columns(iCol).Hidden = False
End If
Next iCol
End With
End Sub

=====
Another approach would be to insert another row and put some kind of indicator
in it (x or leave it blank). Then just loop through the columns in that row.

Dallman Ross wrote:

Short version: I want a macro to hide columns of a certain
cell color and font color.

Long version, which includes my reasons:
I have a sheet with lots of complex formulas and found it has
gotten unwieldy and recalculates all the time now and takes way
too long to do so. I have now revised a lot of the formulas
and added various helper columns to reduce the calculations
per cell and, hopefully, get out of my calculation pickle.
(Haven't quite succeed yet in the latter, though, unfortunately.)
I hide all the helper columns. However, to revise the sheet
I'm unhiding all the hidden columns temporarily. I've formatted
these normally-hidden columns all a certain color and also
changed the font color there, so I can easily distinguish these
as columns to hide again. Now I want a macro to do that for me.

Would someone be kind enough to help me with such a macro?

Here's some pseudo-code:

For nextcol in columns 1-30
If {data range} = Hex Val. #CCCCFF
If {data range} font color = #0000FF
Hide column
End If
End If
End of For-Loop

Dankeschoen!

--
Dallman Ross


--

Dave Peterson