How to hide rows based on cell number

JessicaKinnear

New Member
Joined
Jan 6, 2021
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Hi, Is it possible to hide /unhide rows based on a number in a cell?

I basically have a cell F21 that I would like people to fill in based on how many tenants we have this could be 1 - 40.

If someone types 1 into the box, I'd like row F38 to show, if they type 2 I'd like rows 38 & 39 to show, type 3 38, 39 & 40 to show. And so on all the way up to 40 and row 77.

Is there a code that could make this happen?

Many thanks
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "F21" Then
      Rows("38:77").Hidden = True
      Rows(38).Resize(Target.Value).Hidden = False
   End If
End Sub
This needs to go in the relevant sheets code module
 
Upvote 0
Solution
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "F21" Then
      Rows("38:77").Hidden = True
      Rows(38).Resize(Target.Value).Hidden = False
   End If
End Sub
This needs to go in the relevant sheets code module
great this worked - thank you!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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