Insert Multiple Rows - Popup Box VBA

bmkelly

Board Regular
Joined
Mar 26, 2020
Messages
172
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am looking for a macro that can insert 'x' amount of rows at ActiveCell that will give the user a pop box to enter however many rows they need to insert.

I am currently using this formula

Sub InsertRow()
ActiveCell.EntireRow.Resize(1473).Insert Shift:=xlDown
End Sub


The formula above works fine but would love to make it that much easier for users to have a pop up box appear so they can just insert in 'x' amount of rows instead of going into the Macro and changing the resize number (Example of above they would have to change the 1473 number every time they want to insert)

Thanks!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this:
VBA Code:
Sub InsertRow()
    
    Dim i As Integer
    
    On Error GoTo err_check
    i = InputBox("How many rows would you like to insert?")

    ActiveCell.EntireRow.Resize(i).Insert Shift:=xlDown
    
    Exit Sub
    
err_check:
    MsgBox "You must enter a valid number of rows to insert!", vbOKOnly, "ENTRY ERROR!"
    
End Sub
 
Upvote 0
How about
VBA Code:
Sub bmkelly()
   Dim Rws As Variant
   
   Rws = InputBox("How many rows")
   If Rws = "" Then Exit Sub
   ActiveCell.EntireRow.Resize(Rws).Insert
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,426
Messages
6,119,417
Members
448,895
Latest member
omarahmed1

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