Add Specific number of rows based on cell value

Utradeshow

Well-known Member
Joined
Apr 26, 2004
Messages
800
Office Version
  1. 365
Hi All,

I have this code that adds rows based on the value of cell A2. I need two things. I would like the code to run after the value is entered in cell A2 vs having to press a add button. and also would like it to add rows starting from row 11 down? Is that possible?

VBA Code:
Sub InsertRow()

  Dim ws As Worksheet
  Dim NBOFROWS As Range
  Set ws = ThisWorkbook.ActiveSheet

  With ws
    Set NBOFROWS = .Range("A2")
    ActiveCell.EntireRow.Offset(1).Resize(NBOFROWS.Value).Insert shift:=xlDown
  End With

End Sub
 
(y). Now, please remember to mark the thread as "Solved".
 
Upvote 0
Solution

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You're gonna kill me! I have a pivot table that feeds off this data, I was told to have the Pivot table adjust along with this data, the data sheet should be formatted as a "Table" and now the code doesn't work properly. Is there anything that can be adjusted to have this code add rows to the table?
 
Upvote 0
I have no idea how your real project is organized but this would be a completely different case, I suggest opening a new thread with an appropriate title.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,840
Messages
6,162,311
Members
451,759
Latest member
damav78

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