[英]How to subtract the value of two cells if vlookup matches on two other cells in Google Sheets
Formula to compare B3 in sheet 1 to column A in sheet 2 (Defined Range Name - COUNTY). 将表1中的B3与表2中的A列进行比较的公式(定义的范围名称-COUNTY)。 If they match then subtract the value of A3 from D2 OR compare C3 in sheet 1 to column A in sheet 2 (Defined Range Name - COUNTY). 如果它们匹配,则从D2中减去A3的值,或将工作表1中的C3与工作表2中的A列进行比较(定义的范围名称-COUNTY)。 If they match then add the value of A3 to D2. 如果它们匹配,则将A3的值添加到D2。 This is what I have now and it is not adding or subtracting. 这就是我现在所拥有的,不是加法或减法。 It just carries down the previous total. 它只是保留以前的总数。
=IFERROR(SUMIFS(OR(VLOOKUP($B3,COUNTY),D2-$A3,OR(VLOOKUP($C3,COUNTY),D2+$A3))),D2)
You can do this by using MATCH
combined with an ISERROR
function. 您可以通过将MATCH
与ISERROR
函数结合使用来实现。 In cell D3
, write the following formula: 在单元格D3
,编写以下公式:
=D2 - IF(ISERROR(MATCH(B3,COUNTY,0)),0,A3) + IF(ISERROR(MATCH(C3,COUNTY,0)),0,A3)
You can copy this down in column D. 您可以将其复制到D列中。
The way this works is that it starts with D2
, then subtracts, using an IF
/ ISERROR
: 它的工作方式是从D2
开始,然后使用IF
/ ISERROR
减去:
0
(defined in formula), if U2
(cell B3) isn't in the range COUNTY
because ISERROR
would return TRUE
如果U2
(单元格B3) 不在 COUNTY
范围内, ISERROR
0
(在公式中定义),因为ISERROR
将返回TRUE
4
(cell A3), if U2
(cell B3) is in the range COUNTY
, because ISERROR
would return FALSE
通过4
(小区A3),如果U2
(小区B3)的范围是从COUNTY
,因为ISERROR
将返回FALSE
The second part of the formula works the same way, but with an addition instead. 公式的第二部分以相同的方式工作,但有一个加法。
You can check references for the functions used here: 您可以在此处查看有关使用的功能的参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.