Thread: Hiding Columns
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bill Renaud Bill Renaud is offline
external usenet poster
 
Posts: 417
Default Hiding Columns

I removed the double quotes around the value of "1", since I don't think
they are needed, unless you actually have them formatted as a string.
When setting up the For statement, use Range("A3"), then resize it
horizontally to the number of columns of data.
Note the shortcut way of determining whether the column should be hidden
or not by placing a boolean expression on the right side of the equals
sign.

Public Sub MyHide()
Dim rngCell As Range
Dim lngNumColumns As Long

Application.ScreenUpdating = False

lngNumColumns = ActiveSheet.UsedRange.Columns.Count

For Each rngCell In Range("A3").Resize(1, lngNumColumns)
With rngCell
.EntireColumn.Hidden = (.Value = 1)
End With
Next rngCell

Application.ScreenUpdating = True
End Sub

--
Regards,
Bill Renaud