Need help with macro to hide rows

November 12, 2011 at 07:54:14
Specs: Windows Vista
I've been reading the different forums looking for possible codes that i could interpret and modify in order to get my worksheet to work 'properly' but haven't had any luck.

To put it simply, I have a worksheet that i need help hiding rows for. The rows that will be hidden will vary on the value of a cell in the worksheet. For example: if the value of A1=1 then rows 62-340 should hide, if A1=2 then rows 93-340 should hide, and so on... and if the value is other than the values determined in the formula (ie -1-6, and 7 is placed in the cell), then rows 31-340 should hide. I was able to get the first value of 1 and the exception number (7) to be recognized with the following formula, but can't get it to work with the other 'options'. Please help!

Private Sub Worksheet_Calculate()
If Range("I1").Value = 1 Then
Rows("62:340").Hidden = True
Rows("62:340").Hidden = False
End If
End Sub

See More: Need help with macro to hide rows

Report •

November 12, 2011 at 19:33:59
Just add more IF's, one for each option. The only .Rows.Hidden line that will be executed will be the one for the IF statement that is TRUE.

You should also read up on the use of Select Case. That method is a lot more elegant than a bunch of IF statements. It's probably more efficent also.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •
Related Solutions

Ask Question