Hide rows based on cell value in another row!

sahar

New Member
Joined
Oct 13, 2011
Messages
4
I have a worksheet where the value in the cells B9 and B10 are entered manually. I would like to set up a code where Rows 20 to 25 show up based on the values entered in these cells.

Cell B9 can only have the value of 4 or 6. Cell B10 can have the value of anywhere from 0 to 60.

Here's what I need to do:
If cell B9 is 4 and B10 is 30 or less - rows 20 to 25 to be hidden
If cell B9 is 6 and B10 is 30 or less - Rows 22 to 25 to be hidden
If cell B9 is 4 and B10 is more than 30 - Rows 22 to 25 to be hidden
If cell B9 is 6 and B10 is between 30 and 45 - row 24 should be hidden
If cell B9 is 6 and B10 is more than 30 - all rows should show.

Thank you very much.
 
This should do what you need.
I hope it helps!
All the best,
Franco Musso

If Range("B9").Value = 4 And Range("B10").Value <= 30 Then
Rows("20:25").Select
Selection.EntireRow.Hidden = True

ElseIf Range("B9").Value = 6 And Range("B10").Value <= 30 Then
Rows("22:25").Select
Selection.EntireRow.Hidden = True

ElseIf Range("B9").Value = 4 And Range("B10").Value > 30 Then
Rows("22:25").Select
Selection.EntireRow.Hidden = True

ElseIf Range("B9").Value = 6 And Range("B10").Value > 30 And Range("B10").Value < 45 Then
Rows("24:24").Select
Selection.EntireRow.Hidden = True

End If
 
Upvote 0
Franco, Thank you very much for that code. I pasted it my VBA editor, but it doesn't do anything! Can you tell me what I may be doing wrong.? What I basically did was just right click on my worksheet, click on view code and paste it into the window.
 
Upvote 0
Sorry, I presumed you'd be pasting it into an existing macro.
Here's the whole thing, including the macro name, beginning and end of the sub... Please let me know if it works this time!...

Sub Hide_Row_if_else()
'
' Hide_Row Macro
' Macro recorded 13/10/2011 by francom
'
'
If Range("B9").Value = 4 And Range("B10").Value <= 30 Then
Rows("20:25").Select
Selection.EntireRow.Hidden = True

ElseIf Range("B9").Value = 6 And Range("B10").Value <= 30 Then
Rows("22:25").Select
Selection.EntireRow.Hidden = True

ElseIf Range("B9").Value = 4 And Range("B10").Value > 30 Then
Rows("22:25").Select
Selection.EntireRow.Hidden = True

ElseIf Range("B9").Value = 6 And Range("B10").Value > 30 And Range("B10").Value < 45 Then
Rows("24:24").Select
Selection.EntireRow.Hidden = True

End If
End Sub
 
Upvote 0
Franco I hate to be a bother but...

suddenly the macro has decided not to work after all. I have a macro enabled file and i ran the macro after saving it. But it does not want to work!!! I don't know whats wrong when i ran it the first time it worked fine. Also the workbook is to be protected, I don't know if that is what is causing the problem.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top