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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,032
Messages
6,122,770
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