WorksheetFunction.SumIfs

Yamezz

Active Member
Joined
Nov 22, 2006
Messages
336
Office Version
  1. 2019
What am I doing wrong with the syntax here:
VBA Code:
Qty = Application.worksheetfunction.SumIfs(OpenReport.ActiveSheet.range("D2", "D" & LastRow), _
        OpenReport.Activesheet.range("B2", "B" & LastRow), "True" _
        OpenReport.Activesheet.range("E2", "E" & LastRow), SKU _
        OpenReport.Activesheet.range("I2", "I" & LastRow), DUP)

My intention is to set the Qty variable to the sum of Column D where Column B contains the text "TRUE", Column E is the current SKU being examined and Column I is the current DUP (discounted unit price). My guess was that True was causing a problem, so I tried ""TRUE"", but that didn't help.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
The syntax is fine, as long as SKU and DUP are variables that are either simple data types or single cell ranges.
 
Upvote 0
What is the actual issue?
 
Upvote 0
This is what I get.


2023-12-04.png
 
Upvote 0
Ah - you're missing a comma at the end of the line with True in it.
 
Upvote 0
Me too, given I didn't spot that initially! :)
 
Upvote 0
I've just realised I have a further problem with this code. The part referencing "True" as a criteria is not working. How do I write it correctly so only lines where "TRUE" occurs in column B are summed?
I hadn't realised this was an issue until I got to some data where one of the entries is FALSE and the SUMIF was mistakenly including that row's data.
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,069
Members
449,090
Latest member
fragment

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