if cell empty hide row macro?

T

Todd

Hi, I need a macro that will hide rows if a cell in column AD is empty.

Can anyone help me?


Thanks

Todd
 
T

Tom Ogilvy

You would need a toggle button for that.

If you want to have the command button toggle the rows (each time it is
clicked), you can do

Private Sub CommandButton1_Click()
Dim rng As Range, rng1 As Range
On Error Resume Next
Set rng = Range("AD:AD").SpecialCells(xlBlanks)
Set rng1 = Range("AD:AD").SpecialCells(xlVisible)
On Error GoTo 0
Debug.Print rng.Address
Debug.Print rng1.Address
If Not rng Is Nothing Then
If rng1.Areas.Count = 1 Then
rng.EntireRow.Hidden = True
Else
rng.EntireRow.Hidden = False
End If
End If
End Sub

--
Regards,
Tom Ogilvy


Todd said:
Thank you Tom, I have this set to a command button and it works
wonderfully. Another question about this though. I want to have the button
hide when clicked and unhide if unselected too. How can somethng like this
be done?
 
Top