Row Insert with Marcro

jmattingly85

New Member
Joined
Jul 12, 2010
Messages
33
Office Version
  1. 365
Platform
  1. Windows
I have a Macro that I have recorded that is copying columns H and I, inserting two new columns and moving the previous H and I to J and K. In D3, I have the following formula: =SUMIF($H$2:$AAA$2,"Interest",$H$3:AAA3)

When I run the macro to insert the new columns, the absolute reference to H2 and H3 in the formula change to J2 and J3 - the don't retain their
absolute reference. Is there a way to make that stay at H or do I need to just edit the macro to update the formula?

Thanks!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
My first thought it not to put the formula directly in the sheet, but insert it via the macro after you do all the moving around.
 
Last edited:
Upvote 0
This can be adapted to your code to fix the formula after the columns are inserted. The general idea is to store the formula in a variable, then put back into D3 after the columns are inserted.
Code:
Sub FixFormula()
Dim F As String
F = Range("D3").Formula
Columns("H:I").Insert
Range("D3").Formula = F
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,403
Messages
6,124,714
Members
449,182
Latest member
mrlanc20

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