View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Dallman Ross Dallman Ross is offline
external usenet poster
 
Posts: 390
Default Need a macro to hide certain columns

In , Dave Peterson
spake thusly:

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


That's excellent! I only had to modify it slightly.
It works perfectly! Thank you very much.

The color indexes weren't right, and I had to record a
dummy macro to see what the right ones were. (5 and 24.)
Also, my formatting starts on Row 2. So I changed the "1" cell
refs to "2". Very slick, Dave!

I saw another article here today with someone (you?)
showing how to run through the columns until a blank
is reached. Maybe I'll incorporate that in this instead
of just using my arbitrary "30" column-figure.

One question: what is the "Option Explicit" part for?


===========================
Dallman Ross wrote:

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


[snip of "long version"]


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!