PDA

View Full Version : How to exclude hidden rows/columns while executing a VB code



jameshbabu
01-14-2012, 11:32 PM
Hi all,

i would like to know how to exclude the hidden rows/ columns while executing the VB code,

thanks

marreco
01-15-2012, 03:45 AM
Try..


Sub Macro1()
If Rows("1:10").EntireRow.Hidden = True Then
Rows("1:10").EntireRow.Hidden = False
ElseIf Columns("2:3").EntireColumn.Hidden = False Then
Columns("2:3").EntireColumn.Hidden = True
End If

End Sub

Bob Phillips
01-15-2012, 07:59 AM
Check the hidden property



For i = 2 To 20
If Not Rows(i).Hidden
'do stuff
End If
End With

shrivallabha
01-15-2012, 08:30 AM
Or you can use specialcells method:

Dim rWork As Range
Set rWork = ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible)

Paul_Hossler
01-15-2012, 11:15 AM
Be careful if there are MergedCells.

My experience is that merged cells will lead to unexpected (and oft times, unwanted) results when dealing with hidden rows and columns

Paul