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:

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Code:
Sub InsertRows()
Dim y As Long
y = 5
ActiveCell.EntireRow.Resize(y).Insert
End Sub
 

texasalynn

Well-known Member
Joined
May 19, 2002
Messages
8,458
Code:
Sub InsertInputRows()
     numrows = InputBox("Number of rows")
     ActiveCell.Resize(numrows).EntireRow.Insert
End Sub
 
Last edited by a moderator:

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
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
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,123,318
Messages
5,600,924
Members
414,416
Latest member
Nobu

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
Top