Adding/hiding rows based on value in cell

ryancella

New Member
Joined
Oct 14, 2011
Messages
2
Hi there,

First time posting to the forum, so take it easy on me, alrighty?

I'm working on a workbook with multiple tabs. I am trying to make one of these tabs (called Services) and particularly dynamic one.

In this case, I have values in cells b15, b16, and b17. If b15 has a value of 1+ i would like to display rows 23 through 33. If b16 has a value of 1+ i would like to display rows 36 through 46. And so on...

However, if any of these cells has a value of 0, i want to hide rows 23 through 33 and 36 through 46, respectively.

I'm also trying to avoid making this a 'change event' since I would still like to ability to undo changes.

Help is appreciated.

Ryan
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
My efforts:

Code:
Sub showhiderows()
If Range("B15").Value >= 1 Then Rows("23:33").Hidden = False
If Range("B15").Value = 0 Then Rows("23:33").Hidden = True
If Range("B16").Value >= 1 Then Rows("36:46").Hidden = False
If Range("B16").Value = 0 Then Rows("36:46").Hidden = True
If Range("B17").Value >= 1 Then Rows("49:59").Hidden = False
If Range("B17").Value = 0 Then Rows("49:59").Hidden = True

End Sub

I wasn't sure exactly what you meant by "And so on", so I assumed you wanted B17 to correspond to rows 49:59 - i.e. leaving another gap of 3 rows.
 
Upvote 0
I have a naive reply. So where am I pasting this code? I'm assuming I need to go tools/macros/visual basic editor. Then what? Should I view the code on my specific Sheet (Services)? I'm in over my head, but any additional direction is helpful.
 
Upvote 0
Click the "Developer" tab in the Ribbon (it should be on the right of "View"). If it's not there, click the Excel button (top left), then "Excel options", then check "show developer tab".

Click "visual basic" within the developer tab. Insert module. Paste the code. Then you'll be able to go back to excel and click "Macros", and it should be there.

You'll have to resave as a macro enabled workbook, though. And for that macro you'll have to run it while the Services sheet is active. (Though it's also possible to write it so that that's not the case.)
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,004
Members
452,374
Latest member
keccles

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