Hide row if cell is empty
Hi,
The following code should work fine:
'---------------------------------------------------
Sub HideTheRows()
HideRowsForBlanks Range("A1:A20")
HideRowsForBlanks Range("A25:A30,A35")
End Sub
Sub HideRowsForBlanks(Rg As Range)
Dim cell As Range, rgToHide As Range
'build empty-cell range
For Each cell In Rg.Cells
If cell.Text = "" Then
If rgToHide Is Nothing Then
Set rgToHide = cell
Else
Set rgToHide = Application.Union(rgToHide, cell)
End If
End If
Next
'Hide
If Not rgToHide Is Nothing Then
rgToHide.EntireRow.Hidden = True
End If
End Sub
'------------------------------------------------
--
Regards,
Sébastien
<http://www.ondemandanalysis.com
"Qaspec" wrote:
On a button click I'd like to hide row 4 if a4 is empty. I'd like to this up
to row 20 if the correspondince cell to that row in column a is empty. Thanks.
|