[英]How to use a cell's value (string) as part of a formula in Excel (not within a macro)?
I need to sum a range of values in Excel based on one criterion.我需要根据一个标准对 Excel 中的一系列值求和。
So I want to sum say range B1:B10
based on values of range A1:A10
if the range A1:A10
answers to some criterion eg contains the words "apple - juice fresh"
or "banana"
所以我想总结说范围
B1:B10
基于范围A1:A10
如果范围A1:A10
回答某些标准,例如包含"apple - juice fresh"
或"banana"
So the formula would look like:所以公式看起来像:
=SUMPRODUCT(SUMIF(A1:A10;{"apple - juice fresh";"banana"};B1:B10))
This works as desired.这可以按需要工作。 Now, I don't want to have the list hardcoded in the formula.
现在,我不想在公式中硬编码列表。 I want the list somewhere in a cell.
我想要一个单元格中某个地方的列表。 Say cell
C1
.说单元格
C1
。 And so the cell C1
contains as a value:因此单元格
C1
包含一个值:
{"apple - juice fresh";"banana"}
and I want the formula to be something like:我希望公式类似于:
=SUMPRODUCT(SUMIF(A1:A10;C1;B1:B10))
But this does not work.但这不起作用。 How can I achieve this?
我怎样才能做到这一点? I tried
CONCATENATE(C1)
but it does not work.我尝试了
CONCATENATE(C1)
但它不起作用。
Herebelow is a sample of what I would like下面是我想要的示例
You can try FILTER()
then SUM()
with Excel O365
您可以使用
Excel O365
尝试FILTER()
然后SUM()
=SUM(FILTER(B2:B8,ISNUMBER(SEARCH(A2:A8,D2))))
If you don't have O365
then try SUMPRODUCT()
like如果您没有
O365
,请尝试SUMPRODUCT()
之类的
=SUMPRODUCT(--ISNUMBER(SEARCH(A2:A8,D2)),B2:B8)
Edit: If that is the case then go with
FILTERXML()
.编辑:如果是这种情况,那么 go 和
FILTERXML()
。 Give a try on试一试
=SUM(FILTER(B2:B8,ISNUMBER(XMATCH(A2:A8,FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(D2,"{",""),"}",""),CHAR(34),""),", ","</s><s>")&"</s></t>","//s"),0))))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.