Hide two different sets of rows without macros based on different input criteria

dwharrington

New Member
Joined
Dec 4, 2015
Messages
1
The old thread here on Mr. Excel does mostly what I want to do: hide rows WITHOUT Macros in Excel.

However, I want to do something a little more expansive. I know nothing about VBA, so I need a little help, as I tried to add multiple criteria to the code above and it didn't work.

I have a complex sheet I am creating to calculate space in buildings, and it would be useful to expand/contract the size of it based on the number of buildings the user wants to examine at once: 1-5.

Therefore, an input of 1 in a certain cell should hide two sets of rows; an input of 2 would hide two different sets of rows; and so on.

I'll lay out the logic, and any input would be appreciated. I could learn a lot from this:

If F3= "", then nothing is hidden
If F3= 1, then rows 9:28 and rows 48:98 are hidden
If F3= 2, then rows 14:28 and rows 61:98 are hidden
If F3= 3, then rows 19:28 and rows 74:98 are hidden
If F3= 4, then rows 24:28 and rows 87:98 are hidden
If F3= 5, then nothing is hidden
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You have to use VBA here... how else could you hide the rows?

Code:
Sub hideStuff()

'this is just to reset to begin
Rows("9:98").Hidden = False


Select Case Range("F3").Value
    Case Is = 1
        Rows("9:28").Hidden = True
        Rows("48:98").Hidden = True
    Case Is = 2
        Rows("14:28").Hidden = True
        Rows("61:98").Hidden = True
    Case Is = 3
        Rows("19:28").Hidden = True
        Rows("74:98").Hidden = True
    Case Is = 4
        Rows("24:28").Hidden = True
        Rows("87:98").Hidden = True
    Case Else
        Rows("9:98").Hidden = False
End Select


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,034
Messages
6,122,782
Members
449,095
Latest member
m_smith_solihull

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