Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50079

VBA to insert rows in named range only

$
0
0
Hi All,

I have attached the following code which allows the user to insert a user-defined number of rows in a sheet, however, I would like to control this insert function to a specified name range. Any idea's how this can be achieved?

Let say the named range is "Labour_Insert_Range" for example.

Code:

Sub Insert_Rows()
 
    Dim Rng, n As Long, k As Long
    Application.ScreenUpdating = False
    Rng = InputBox("Enter number of rows required.")
    If Rng = "" Then Exit Sub
    ActiveSheet.Columns.Hidden = False
      Range(ActiveCell, ActiveCell.Offset(Val(Rng) - 1, 0)).EntireRow.Insert
    k = ActiveCell.Offset(-1, 0).Row
    n = Cells(k, 744).End(xlToLeft).Column
    Range(Cells(k, 1), Cells(k + Val(Rng), n)).FillDown
   
    Search_Date_Hide_Columns
   
End Sub

Thanks in advance,

Viewing all articles
Browse latest Browse all 50079

Trending Articles