Macro to Hide/unhide a row


Posted by Caliche on February 07, 2002 2:18 PM

Could you please give me an example of a macro for hiding/unhiding rows in a worksheet depending on a cell value ( for example if a1=1)?

Thanks a lot for your help.

Posted by Jim on February 07, 2002 3:43 PM

Hi Caliche,

Try this:

Sub Macro1()
If [A1].Value = 1 Then
Range("C4:G4").EntireRow.Hidden = True
End If

If [A1].Value > 1 Then
Range("C4:G4").EntireRow.Hidden = False
End If
End Sub

Post again, if you need more

Jim



Posted by Caliche on February 08, 2002 8:35 AM


Thanks, Jim. It worked fine.

I have an additional question: How will look the macro case I need to hide/unhide row "i" depending on the value of cell A("i",1)?. I don't know in advance how many rows I must hide/unhide. I suppose I must obtain this number (it depends of the range of rows selected)and have a loop, but I don't know how will be the code to do this.

Thanks in advance.

Caliche