Detect Hidden Columns

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I detect if any columns have been hidden on a worksheet in vba?

I would like to use this to prevent a modal form (called from wsheet1)
initialising and also in a Workbook_BeforeClose event which contains 4
wsheets.

Geoff
 
Sub geoff()
For i = 1 To 256
If Columns(i).EntireColumn.Hidden = True Then
MsgBox ("column " & i & " is hidden")
End If
Next
End Sub
 
Given that people are using v2007 now, it would be better not to hard code
the row count:

Private Sub CommandButton1_Click()
Dim i As Long

With ActiveSheet.Columns
For i = 1 To .Count
If .Item(i).EntireColumn.Hidden = True Then
MsgBox "column " & i & " is hidden"
End If
Next
End With

End Sub

NickHK
 
Collections have a member of .Item.

..Columns(i) is equivalent to .Columns.Item(i)

Only so I could include both in the With block.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

before save event 2
Sort Method 3
Add-in 2
SheetSelectionChange 7
Show and Hide Forms 8
Use of Cell Values Instead of Hard Coding 6
Problems with Protect Method 8
CodeName assignment for the new Worksheet. 4

Back
Top