VBA - Insert rows above active cell

RE Dev

New Member
Joined
Mar 11, 2015
Messages
6
Hello, right now, I have a macro that works great where I can insert x number of rows at the bottom of a range. The first line in the range is a row of formulas and this row gets copied into all the rows that are added. What I'm looking to do is be able to add these x rows above the selected/active cell instead of at the end. I cannot figure it out for the life of me.

Existing macro:

Sub Add_Budget_Item_02()

Call Begin

Set Irs = wsInputs.Range("Budget_Item_02")
Set Ire = wsInputs.Range("Budget_Item_03")
Set Brs = wsBudget.Range("Budget_02")
Set Bre = wsBudget.Range("Budget_03")

'Determine how many lines to add to the category
NumItems = Application.InputBox( _
Prompt:="How many items would you like to enter?", _
Title:="Enter Line Items", _
Type:=1)

If NumItems = False Then Exit Sub

'Add line item to input tab budget item
Ire.Offset(-1, 0).Resize(NumItems, 1).EntireRow.Insert
Irs.Offset(1, 0).EntireRow.Copy Destination:=Ire.Offset(-NumItems - 1, 0).Resize(NumItems, 1).EntireRow
Ire.Offset(-NumItems - 1, 0).Resize(NumItems, 1).EntireRow.Hidden = False

'Add line item to budget tab budget item
Bre.Offset(-1, 0).Resize(NumItems, 1).EntireRow.Insert
Brs.Offset(1, 0).EntireRow.Copy Destination:=Bre.Offset(-NumItems - 1, 0).Resize(NumItems, 1).EntireRow
Bre.Offset(-NumItems - 1, 0).Resize(NumItems, 1).EntireRow.Hidden = False

Ire.Offset(-2, 2).Select

Call Done

End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I tried counting the rows from the end of the range (Ire) to the activecell, which works, but as the macro keeps working, the activecell changes. Ideally I'd be able to get the # of rows between the end and active cell, say 5 for example, and then use 5 as my reference number through the rest of the macro. I can't figure out how to do that.
 
Upvote 0
Wow all it takes is asking for help for it to click I guess. I ended up putting the value of the rows between active cell and end into a named range cell and then referencing that named range cell value and then clearing it out at the end of the macro.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,811
Messages
6,181,082
Members
453,021
Latest member
Justyna P

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