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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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
 
Upvote 0

Forum statistics

Threads
1,215,470
Messages
6,124,993
Members
449,201
Latest member
Lunzwe73

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