SUMIFS #REF error once macro executed

davidhall

Board Regular
Joined
Mar 6, 2011
Messages
174
I have a sumifs formula in sheet 2 where the sum range and criteria ranges are in sheet1. The criteria are on sheet 2. When I initially input the formula on sheet 2, it works fine, however, when I run a certain macro, the formula messes up.

The purpose of the macro is to format things correctly on sheet1 when I import new data. So, I import new data on sheet1, execute the macro, the data is formatted correctly so the referenced material in the sumifs formula can refer to the correct data.

Not sure why its giving me an error.

It looks like this originally = sumifs(Sheet1!G:G,Sheet1!,Indirect("Sheet2!A1"),Sheet1!A:A,Indirect("Sheet2!A2"))

The columns highlighted in red are showing the #REF once the macro is run. The reason why I put the entire column as the reference area is because the data I import varies on how far down it is.

Any suggestions?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Does you macro remov certain rows and/or columns? Those you use in the SUMIFS?
 
Upvote 0
Yes, it does remove columns on sheet1 which are referenced by the sumifs formula.

Then you know the source of you REF errors...

Can you set the SUMIFS function again in code, AFTER the macro has run?
 
Upvote 0
Yeah, I guess I could do that. Are there no ways to prevent the #REF with the Sumifs formula when columns get deleted. I have made the columns an absolute reference and that doesn't really make a difference after the macro executes.
 
Upvote 0
I'm able to do this formula with a vlookup and a named range prior to the macro running. However, the same issue occurs. Is there no workaround with these formulas when columns get deleted?
 
Upvote 0
Which columns do you delete in the macro?
 
Upvote 0
I delete several including A and G which the sumifs formula originally references. After the macro executes, the proper data is columns A and G.
 
Upvote 0
Sorry to be thick on this, but I do not understand why you delete columns on that formulas reference. What is the logic in fact?

Probably we need to know this to present a workaround, because if you do not want to set the same SUMIFS formula after the macro runs (my previous suggestion) then it will always give you the REF errors. Unless you use other formulas; try an INDEX function with a number for the column. The big disadvantage is that INDEX is a volatile function. But it might work.
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

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