View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy Doug Glancy is offline
external usenet poster
 
Posts: 770
Default Combo column identifier

Dave,

Try this. It qualifies the ranges each time through with "wksht" otherwise
you would be referring to the first sheet each time. I also changed the
"wksht" declaration from "Object" to "Worksheet." Finally, I added a test
to make test whether it found "top" in row 3, if not it skips the next
steps.:

Sub AllSheetsColHide()
'for all sheets in currently active workbook, assigned to button

Dim TopCell As Range
Dim TopCol As Range
Dim Cols2Hide As Range
Dim wkSht As Worksheet

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
Set TopCell = .Rows(3).Find(What:="top", LookIn:=xlValues)
If Not TopCell Is Nothing Then ' if it found "top"
Set TopCol = .Columns(TopCell.Column)
Set Cols2Hide = .Range(TopCol, .Columns("AC"))
Cols2Hide.Hidden = True
End If
End With
Next wkSht

End Sub



hth,

Doug
"davegb" wrote in message
oups.com...
I've been modifying the code Doug gave me to hide the columns in every
worksheet in the workbook. But I'm getting an error, "Object variable
or with block variable not set" when I run the following:

Sub AllSheetsColHide()
'for all sheets in currently active workbook, assigned to button

Dim TopCell As Range
Dim TopCol As Range
Dim Cols2Hide As Range
Dim wkSht As Object

For Each wkSht In ActiveWorkbook.Worksheets

Set TopCell = Rows(3).Find(What:="top", LookIn:=xlValues)
Set TopCol = Columns(TopCell.Column)
<------------------------[error here]
Set Cols2Hide = Range(TopCol, Columns("AC"))
Cols2Hide.Hidden = True

Next wkSht

End Sub

Any suggestions? Thanks in advance!