Insert given numbers of rows above selected row

gopal baheti

New Member
Joined
Dec 2, 2014
Messages
34
Need to Insert rows given in Cell A1 above active row.
If i select row no 1000 and cell A1 Contains 5 then insert 5 rows above row no. 1000.
Regards
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this:

Code:
Sub Insert_Rows()
Application.ScreenUpdating = False
Dim ans As Long
Dim nr As Long
nr = Selection.Row
ans = Range("A1").Value
Rows(nr).Resize(ans).Insert xlShiftUp
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This modified version assures a numeric value is in Range ("A1")
And that the value is greater then (0)
Code:
Sub Insert_Rows()
Application.ScreenUpdating = False
Dim ans As Long
Dim nr As Long
nr = Selection.Row
    If IsNumeric(Range("A1")) = True And Range("A1") > 0 Then
        ans = Range("A1").Value
        Rows(nr).Resize(ans).Insert xlShiftUp
        Else
        MsgBox "Inproper value in Range(A1)"
    End If
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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