VBA Copy formula without changing reference

csb31

New Member
Joined
Feb 23, 2012
Messages
5
Hello I have a simple macro to copy a row and insert below. Works like a charm. However...

Code:
Sub AddRow()
'
'
'
    ActiveCell.EntireRow.Copy
    ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
    Selection.Insert Shift:=xlDown
 
End Sub

This alters the formulas relative references. This is what I want EXCEPT for the formula in the A column cell. When I insert this new row I want the formula in the A cell from the original row to copy EXACTLY, not to shift, to the A cell in the new row. If the formula is =B3 in the original I want it to be =B3 in the new row, NOT =B4 etc. The formula in the A column is not consistent across the sheet so it has to pull it from the cell, the macro can't provide it. For reasons related to other macros and functions I can't just use $ absolute references. Any advice. I tried to record a few macros to get an idea but it hasn't worked. Thanks in advance!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try:

Code:
Sub AddRow()
    With ActiveCell
        .EntireRow.Copy
        .Offset(1, 0).EntireRow.Insert Shift:=xlDown
        .EntireRow.Cells(2, 1).Formula = .EntireRow.Cells(1, 1).Formula
    End With
End Sub
 
Upvote 0
One way:

Code:
Sub AddRow()
    With Cells(ActiveCell.Row, "A")
        .EntireRow.Copy
        .Offset(1).Insert
        .Offset(1).Formula = .Formula
    End With
    Application.CutCopyMode = False
End Sub
 
Upvote 0
Success. They both worked. Thanks a ton, I knew it couldn't be super difficult. Thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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