带条件数组的 Sumif

发布于 2024-11-23 16:54:12 字数 419 浏览 1 评论 0原文

我很惊讶我在任何地方都找不到这个,这让我觉得我一定是错误地处理了这个问题。我希望能够在 sumifs 中包含一系列值,以便它对条件中的每个值执行类似循环的操作(无需为每个值编写“ +sumifs(....)”。这是我的示例到目前为止还不起作用

`=SUMIFS(Sum,Range1,Criteria1, '[Stores.xlsx]Sheet1'!$H:$H, "Store #"&Regions!$T:$T&"*")`

所以我试图传递 Regions!T:T 中的每个值作为标准。
例如,“Store #150 Los Angeles”和“Store #155 San Diego”都需要通过参数传递。目前,该公式仅返回匹配的第一个项目,不会继续到下一个项目。
我希望这是有道理的。请询问您是否需要更清晰的信息。

I'm surprised I can't find this anywhere which makes me think I must be going about this incorrectly. I want to be able to include a series of values within sumifs so it performs like a loop for each value in the conditional (without having to write a " +sumifs(....) for each value. Here's an example of what I have so far that is not working

`=SUMIFS(Sum,Range1,Criteria1, '[Stores.xlsx]Sheet1'!$H:$H, "Store #"&Regions!$T:$T&"*")`

So I'm trying to pass every value in Regions!T:T as a criteria.
For example "Store #150 Los Angeles" and "Store #155 San Diego" would both need to be passed through the argument. Currently the formula just returns the first item it matches and doesn't continue to the next item.
I hope that makes sense. Please ask if you need more clarity.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一桥轻雨一伞开 2024-11-30 16:54:12

我认为最简单的方法是在 T 列旁边启动一个“中间”列,对该列的每一行执行 sumifs,然后将该列求和到另一个单元格中。表格甚至数组总和在这里也可能有帮助。

我在 VBA 中提出了以下内容,但我无法完全测试它:

Option Explicit
Function SumSumIfs(ByVal inp As Range) As Integer

    Dim i As Integer
    Dim QBData As Worksheet
    Dim Stores As Worksheet

    Set QBData = Workbooks.Open("QBData.xlsx").Sheets("Sheet1")
    Set Stores = Workbooks.Open("Stores.xlsx").Sheets("Sheet1")

    Dim QBRange1, QBRange2, SalesRange As Range

    Set QBRange1 = QBData.Range("H1:H" & Range("H1").End(xlDown).Row)
    Set QBRange2 = QBData.Range("I1:I" & Range("I1").End(xlDown).Row)
    Set SalesRange = QBData.Range("H1:H" & QBData.Range("H1").End(xlDown).Row)


    For i = 1 To inp.End(xlDown).Row
      SumSumIfs = SumSumIfs + Application.WorksheetFunction.SumIfs(QBRange1, QBRange2, _
                  "=" & Stores.Cells(16, 5), StoreRange3, "=" & inp.Cells(i, 19))
    Next i

End Function

同样,我确信有一种方法可以使用公式进行循环,但四处搜索,这对我来说并不明显。

I think the easiest is to start an "intermediate" column next to the T column, do a sumifs for each of the rows of that column, and then sum that column into another cell. Tables or even just array sums may also be helpful here.

I came up with the following in VBA, but I cannot test it completely:

Option Explicit
Function SumSumIfs(ByVal inp As Range) As Integer

    Dim i As Integer
    Dim QBData As Worksheet
    Dim Stores As Worksheet

    Set QBData = Workbooks.Open("QBData.xlsx").Sheets("Sheet1")
    Set Stores = Workbooks.Open("Stores.xlsx").Sheets("Sheet1")

    Dim QBRange1, QBRange2, SalesRange As Range

    Set QBRange1 = QBData.Range("H1:H" & Range("H1").End(xlDown).Row)
    Set QBRange2 = QBData.Range("I1:I" & Range("I1").End(xlDown).Row)
    Set SalesRange = QBData.Range("H1:H" & QBData.Range("H1").End(xlDown).Row)


    For i = 1 To inp.End(xlDown).Row
      SumSumIfs = SumSumIfs + Application.WorksheetFunction.SumIfs(QBRange1, QBRange2, _
                  "=" & Stores.Cells(16, 5), StoreRange3, "=" & inp.Cells(i, 19))
    Next i

End Function

Again, I'm certain there's a way to do this looping with the formula, but searching around, it was not evident to me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文