Excel if statement for 3 columns

2019-08-31 10:59发布

I know this question has been already asked a few times, but every statement that I try I end up with error messages.

I need a simple excel if statement where I can try out 3 possibilities:

Dates

I need to check 3 date columns, A1, B1 and C1. If all 3 are fullfilled, I need to subtract either C1 or B1 by A1. If B1 is empty, then I need to subtract C1 by A1. If C1 is empty, then I need to subtract B1 by A1. By all other results I need 0 to be returned.

Can anyone help me with that? I'm using excel 2016.

I tried the following statement: =IF(B2<>"";B2;C2)-A2

But it doesn't really cover all cases.

标签: excel
2条回答
可以哭但决不认输i
2楼-- · 2019-08-31 11:00

Same result for sample as accepted 'Excel Version' A except for all 3 are fullfilled case:

=IF(A1="",0,MAX(A1:C1)-MAX(MIN(A1:C1),0))

Assumes Brazilian date formats.

Whatever the garbled English is supposed to mean (there is an SE site for a Portuguese version of SO) the results of the first two rows are not required to be the same:

The second row of the example is blank for (I assume, since OP has not bothered to clarify cell references) C1, hence:

If C1 is empty, then I need to subtract B1 by A1

The first row is however populated in all three cells, hence:

If all 3 are fullfilled, I need to subtract either C1 or B1 by A1

In the first row (and indeed all rows in the sample) B1 and A1 are not the same. So for that row there are two different results, which therefore cannot both be the same as any other (single) result, such as whatever is the result for the second row.

查看更多
欢心
3楼-- · 2019-08-31 11:15

Math Version

=IF(OR(AND(A1<>"",B1<>"",C1<>""),AND(A1<>"",B1<>"",C1="")),B1-A1,IF(AND(A1<>"",B1="",C1<>""),C1-A1,0))

Excel Version

=IF(OR(COUNT(A1:C1)=3,AND(ISBLANK(C1),COUNT(A1:B1)=2)),B1-A1,IF(AND(ISBLANK(B1),COUNT(A1:C1)=2),C1-A1,0))
查看更多
登录 后发表回答