Row Insert with Marcro

jmattingly85

New Member
Joined
Jul 12, 2010
Messages
37
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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