want to inerst a row for 5 times

rvkcools

Board Regular
Joined
Mar 14, 2013
Messages
78
i would to insert a row in excel using vba based on a y value

if insert.row = y(any value) then those many rows should insert
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Code:
Sub InsertRows()
Dim y As Long
y = 5
ActiveCell.EntireRow.Resize(y).Insert
End Sub
 
Upvote 0
Code:
Sub InsertInputRows()
     numrows = InputBox("Number of rows")
     ActiveCell.Resize(numrows).EntireRow.Insert
End Sub
 
Last edited by a moderator:
Upvote 0
try below
Code:
Sub InsertRows()
On Error GoTo ERR_R
Dim InsR As Long
InsR = Application.InputBox("Enter How Many Row Want To Insert", "Row Insert")
ActiveCell.Offset(1, 0).EntireRow.Resize(InsR).Insert
Exit Sub
ERR_R:
If Err.Number = 13 Then
MsgBox "Please Enter Only Numeric Value", vbCritical
End If
End Sub
 
Upvote 0
You can eliminate the whole error capture code, if you specify the type for Application.InputBox

Code:
Sub InsertRows()
Dim InsR As Long
InsR = Application.InputBox("Enter How Many Row Want To Insert", "Row Insert", Type:=1)
If InsR > 0 Then ActiveCell.Offset(1).EntireRow.Resize(InsR).Insert
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,084
Members
448,943
Latest member
sharmarick

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