简体   繁体   中英

How to SUM a range in Excel based on CELL/INDEX/MATCH

I am trying to sum a range in Excel. I want users to be able to enter a date in one cell. Then I want to sum a range based on a static starting cell location and the corresponding location based on the date they enter. For example, if they enter 1/3/2021 for the report date, I want to sum the range between B2 and B4 to get $14. I have the following formula which gives me an error. Any ideas on how to get this formula to work as expected? Thanks for your help!

=SUM(B2:CELL("address",INDEX(A2:B63,MATCH(G1,A2:A63,1),2)))

在此处输入图像描述

在此处输入图像描述

Date Sales Misc Column Misc Value
1/1/2021 $3 Report Date 1/4/2021
1/2/2021 $6 Sales Total Formula =SUM(B2:CELL("address",INDEX(A2:B5,MATCH(D2,A1:A5,1)2)))
1/3/2021 $5 Sales Total (expected value) $21
1/4/2021 $7 Sales Total (actual value) I get an error

If your dates are sorted:

=SUMIFS(B:B,A:A,"<="&D2)

在此处输入图像描述

If not:

=SUM(B2:INDEX(B:B,MATCH(D2,A:A,0)))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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