SUMIF In macro code

coop123

Board Regular
Joined
Dec 18, 2018
Messages
66
Office Version
  1. 365
Hello

I have a sumifs formula as part of a macro code.

ActiveCell.Formula = _
"=SUMIFS(N$12:N$" & ListEnd & ", $A$12:$A$" & ListEnd & ",""Non EU"",$B$12:$B$" & ListEnd & ",""="" & M706)"

This works perfectly, but cell M706 could be higher or lower depending on the data within the report each time it is run, hence using ListEnd.

I tried replacing & M706 with & RC[-1] when running it stops with error Application-Defined or Object-Defined error.

Can someone point out where I have made the mistake or how I can change the formula so it works.

Thanks in advance.

coop123
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Should M706 be col M row ListEnd?
 
Upvote 0
I am trying to sum values in column N which match criterial "Non EU" from column A and match value in cell adjacent to formula cell from column B.

1612280795547.png

Starting position will always be column N but could be any row.
 
Upvote 0
What determines which row in col M the formula should look at? is it the ListEnd row?
 
Upvote 0
See code below that positions cell formula is entered in. Cell looked at for Criteria 2 is 1 cell to the left.

Range("M" & ListEnd + 10).Select
ActiveCell.Offset(0, 1).Select
 
Upvote 0
Ok, how about
VBA Code:
With Range("N" & ListEnd + 10)
   .Formula = _
      "=SUMIFS(N$12:N$" & ListEnd & ", $A$12:$A$" & ListEnd & ",""Non EU"",$B$12:$B$" & ListEnd & ",M" & .Row & ")"
End With
 
Upvote 0
Solution
Thank you Fluff, that piece of code works brilliantly, it has solved the problem I have been having.

Thanks again

Coop123
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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