Excel Macro to add a new row two rows above a cell with a named range.

Mrs_Sant0s

New Member
Joined
Aug 27, 2020
Messages
7
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
Platform
  1. Windows
Hi there. Hope someone can help. I have a specified cell which i have given a named range ("Demo_Total"), and I want to create a macro that will add a new row two rows above the named range cell and also copy the formula of an existing row above that.

I created the following, which allows me to find the named range and add a row directly above, but I can't work out how to make it two rows above, and how to copy the formatting from another row.

Application.Goto Reference:="Demo_Total"
Selection.EntireRow.Insert
End Sub

Hope someone can point me into the right direction?

Thanks!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Not sure about the formatting, but this should do as you wish, to insert the row.
NB test on a COPY of your work, first!
VBA Code:
Sub insert_row_above()
With ActiveSheet
    .Cells(.Range("Demo_Total").Row - 2, 1).EntireRow.Insert
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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