Hide / Unhide a Number of Rows Based on Value in Cell

jason55

New Member
Joined
May 22, 2017
Messages
9
Hi guys, hope you can help me out here as I'm new to VBA. I'm trying to forecast tenant rent rolls for a property and have set for a max of 50 tenants. But based on a numerical value in a cell, which denotes how many tenants there are, I would like to hide the unused rows in the worksheet. E.g. if there are only 10 tenants, I would like the remaining 40 rows to be hidden. Below is an extract of what I have done, and the list goes down to 50 cases which is quite tedious. Wondering if there's a better way to do this? Thanks guys! Really appreciate your help on this. :)

Rows("10:61").EntireRow.Hidden = True


Select Case Range("A1").Value
Case Is = 1
Rows("10:11").EntireRow.Hidden = False
Case Is = 2
Rows("10:12").EntireRow.Hidden = False
Case Is = 3
Rows("10:13").EntireRow.Hidden = False
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Rows("10:61").Hidden = True
Rows("10:" & 10 + [A1]).Hidden = False
 
Upvote 0
That would be Row 11 JoeMo.
Untested.
Code:
Sub HideIf()
Application.ScreenUpdating = False
Rows("11:50").Hidden = True
Rows("11:" & 11 + Range("A1").Value - 1).Hidden = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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