Automatically add rows to a spreadsheet

kshaub

Board Regular
Joined
Jun 2, 2005
Messages
51
I want to be able to select a number from a dropdown in a cell and then unhide that number of rows immediately below that cell. I've created a dropdown with 1,2,3,4...20. So if the dropdown is in B3 and I select 3, I want the 3 rows hidden immediately beneath 3 to be unhidden (row 4, 5, and 6). Any suggestions for VBA or some commands?

Thanks in advance.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Macropheliac

Board Regular
Joined
Aug 26, 2005
Messages
165
Add this to the Worksheet's Private Module:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Target.Address = "$B$3" Then Exit Sub
Dim RowNum As Long
RowNum = Target.Value
  Target.Offset(1).Resize(RowNum).EntireRow.Hidden = False
End Sub

How To:

-Select the desired worksheet
-Right-Click the sheet tab
-Choose View Code
-Paste the code


I hope it works for you,

Mac
 

Forum statistics

Threads
1,137,199
Messages
5,680,118
Members
419,883
Latest member
overhear

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
Top