简体   繁体   English

索引/匹配并基于匹配求和范围

[英]Index/Match and sum a range based on match

Good morning. 早上好。 Have tried asking this several times with no success. 曾尝试多次询问,但均未成功。

I have written VBA code with several index/matches . 我用几个index/matches编写了VBA代码。

pasterOH = "=IFERROR(IF(RC[-3]=""Subtotal"","""",IF(RC[-4]="""",INDEX(" & stapler & OH1 & "'!" & "C" & (Month(Worksheets("SEL Onsite OH").Cells(6, 6).Value) + 6) & ",MATCH(RC[-3], " & stapler & OH1 & "'!C3,FALSE),1),INDEX(" & stapler & OH1 & "'!" & "C" & (Month(Worksheets("SEL Onsite OH").Cells(6, 6).Value) + 14) & ",MATCH(RC[-4], " & stapler & OH1 & "'!C2,FALSE),1))),""0"")"

The code works fine to look up a cell in the column that I have specified and return a dollar value if it is a match. 该代码可以很好地在我指定的列中查找单元格,如果匹配则返回美元值。

Here is my issue: I need to be able to sum all of the dollar values to the left of the match. 这是我的问题:我需要能够将匹配项左侧的所有美元值相加。 For example, in the picture I posted a simple picture of a table with index/match . 例如,在图片中,我发布了一张带有index/match的表格的简单图片。 In the formula the target is column E:E, whereby "tom' returns "5". What I am trying to do is if excel can find and match "tom" in column 5, it would sum B2,C3,D4,E5. I could write this if I knew what column "tom" would be in every time. I need to have a VBA solution that goes along with the pasterOH from above that will allow me to sum the values of column 7 (January) picked by my (Month(Worksheets("SEL Onsite OH").Cells(6, 6).Value) + 6) through whatever column the month happens to be. 在公式中,目标是E:E列,其中“ tom”返回“ 5”。我想做的是,如果excel可以在第5列中找到并匹配“ tom”,那么它将求和B2,C3,D4,E5如果我每次都知道“ tom”列将是什么,我可以编写此代码。我需要一个VBA解决方案,该解决方案与上方的pasterOH一起使用,这样我就可以将第7列(一月)的值求和。我的(Month(Worksheets("SEL Onsite OH").Cells(6, 6).Value) + 6)通过月份的任意一列。

For example, In May, the column I am looking up and returning a match to is column 11. I would like the code to start with the matching entry (our "tom" in this case), and sum the results of Jan- May (columns 7-11) and return that as the answer instead of tom's result only in May. 例如,在5月中,我正在查找并返回匹配项的列是第11列。我希望代码以匹配项(在本例中为“ tom”)开头,并对1月至5月的结果求和(第7-11栏),并将其作为答案(而不是仅在五月份的tom结果)返回。

Hope that is clear. 希望很清楚。 I posted a couple of times and found this answer, but don't know if it will apply or how to edit my VBA formula. 我发布了几次,找到了这个答案,但不知道它是否适用或如何编辑我的VBA公式。

Thanks for any assistance 感谢您的协助

Extending a conditional index-match to sum across a range 扩展条件索引匹配以在范围内求和

Sample table pic 样品表图片

您想要的公式是

=SUM(INDEX(B:F,MATCH(C11,A:A,0),0))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM