How to make Excel "IF" formula calculate blank cells as "0"? - excel

How do I make the IF function consider blank cells as "0".
Here is the formula I am using in the H column cells: IF(E1>F1,"YES","NO")
Here is the specific Example:
E | F |G | H |
10 | 0 |30 | YES |
10 | 5 |10 | YES |
10 |-------|-------| NO |
H3 should return "YES" I would think.
In this scenario I cannot change the blank cells to "0", they have to remain blank.
What would be the correct formula for me to use?
I have tried searching around on google and stackoverflow, but the only things I can find are where people are trying to NOT have blanks be considered "0".

=IF(ISBLANK(F1),"YES",IF(E1>F1,"YES","NO")) - Will check for a blank cell, this will work if column F is not formulated
=IF(F1="","YES",IF(E1>F1,"YES","NO")) - Performs a similar check but for the set value "" which is a formulated forced blank cell
=IF(ISNUMBER(F1),IF(E1>F1,"YES","NO"),"YES") - Sense check for if the cell is a number (In case the formulated column is a numerical calculation)

The excel handles automatically for blank cells .
If you enter text it will show error and suggest for correction.
the formaula i use in this examle is
=IF(A1>=B1,"Yes","No")
The result appear as follow

Related

How to do multi-column match in Excel

I have a spreadsheet that looks like this:
A B C D
------------------------------------
1 | Yes | No | | | |
2 | 1 | 1 | 0 | 1 | 0 |
------------------------------------
------------------------------------
12| Yes | No | | Yes | Yes |
13| Yes | Yes | No | No | |
14| Yes | No | | No | Yes |
15| No | Yes | No | No | |
...
I want to fill the cells in Row 2 with a 1 or 0 depending on several criteria. The value should be 1 if all of the following are met (using cell D2 as a reference):
All previous values in Row 1 should match at least one entry in the table starting at D12. For cell D2, this means A1:C1 should exactly match columns A:C in at least one row of the table.
For any of the matching rows from #1, there should be a non-empty value in the same column as the cell being evaluated. So cell D2 would look for a non-empty value in Column D of any rows that match the criteria in #1.
If either of these conditions fails, the cell value should be 0. In Cell D2 we have a value of 1 because the algorithm finds a match in rows 12 and 14 and a non-empty cell in D12 and D14.
I'll need to be able to apply this dynamically across several columns so I'm trying to avoid writing a column-specific function. I realize I could probably write a UDF to perform this, but I wanted to avoid going that route if possible.
Because this was a challenge I had a go at it and came up with
=SIGN(SUM(--(MMULT(($A1:A1=$A12:A15)*(B12:B15<>""),TRANSPOSE(COLUMN($A12:A15)^0))=COLUMNS($A1:A1))))
to be entered in B2 and pulled across. This has to be entered as an array formula using CtrlShiftEnter
A2 I think is just
=sign(counta(a12:a15))
because it will be 1 unless the whole column is empty.
I'm not sure there's a complete answer to your problem as stated without a UDF, but I'd question the method a bit and say "why complicate with 'AND this column isn't blank (but could be any other value)?"
Why not just look for a row match from that field backward? Seems to me it would just shift things by a column, and in fact, this is exactly what you're doing in A2 anyway, since there's nothing before A. So matching on duplicate rows for example, D2 would contain basically the same information as your example has in C2.
To look for duplicates across fields, you could use something like this formula that would go in C2: =IF(SUMPRODUCT((A3:A15=A1)*1,(B3:B15=B1)*1,(C3:C15=C1)*1)>1,1,0)
In D2, you'd copy that formula and add (D3:D15=D1)*1, etc.

How to find if value exists in column 2 given criteria for column 1?

So you know how there is a sumifs function where you only sum the values in which each column's criteria is met?
What is the formula for finding if a value exists in the spreadsheet after each column's criteria is met?
For example:
Column A | Column B
A | Green
A | Blue
A | Green
B | Red
B | Red
B | Red
B | Green
B | Yellow
C | Blue
C | Green
C | Red
I want to find if Blue exists given that column A's value is "B" In this case it does not exist. I prefer not to use VBA if possible.
Given I am understanding your question properly I would give this formula a try.
You can use the COUNTIFS function to achive your desired result. Just place this formula anywhere except columns "A" and "B" in the same sheet.
=COUNTIFS(A:A,"B",B:B,"Blue")
You can nest your COUNTIFS into an IF statement to produce a more readable result.
=IF(COUNTIFS(A:A,"B",B:B,"Blue")>0,"Found","Not Found")
EDIT: Included IF statement

Formatting so that cell is colored differently if it matches any value in column A, or column B, or both?

I have tried solving this myself for some time and it just isn't working for me. It's a somewhat specific goal I have so I haven't had much success finding examples online, so I'm hoping for some direction on how best to approach this. I'm hoping to find a solution that uses VBA. I'm pretty new to VBA so bear with me please!
I am dealing with conditional background coloring based on matching cell values. I have three variable-length columns: A, B and D. Columns A and B are randomly selected subsets of the values that are in column D - so, the values in the different columns may match, but they probably won't be on the same row.
When a cell's value in column D matches that of a cell in column A, I want that cell's row from column D to column K to be colored blue. Likewise, if the cell's value in column D matches a value in column B, I would like it colored red. If a cell in column D matches a cell in both column A and B, I would like it colored purple.
Does that make sense? How would you suggest I approach this?
Let me know if I need to clarify further. I would greatly appreciate any help!
Using Excel 2013.
I have not actually seen your file, since I am at work, but I guess your table looks like this:
| A | B | C | D |
| 1 | 3 | | 1 |
| 3 | 5 | | 2 |
| 2 | 4 | | 3 |
| | | | 4 |
| | | | 5 |
I rather like simple formula based approaches for that, but I could give you a vba example too.
With this setup I propose to use VLOOKUP. You basically check, if the value is part of A, part of B and then you can do the rest with your conditional formatting.
So if additional columns are no problem, just use the lookup to generate a true or false answer (I apologise for formula mistakes, since I use a german excel version):
=NOT(ISERROR(VLOOKUP(D1,A:A,1,False)))
This will tell you TRUE, if there is a value in ALL of column A, that is equal to D1. If you also use this formula for column B you can base your colorcoding for blue and red on these two.
For the purple color you just need to compare the other two results again with a simple AND
Hope that is clear enough and I have read your question right.
Kaz

Excel matching multiple cells for duplicates

I need to populate a cell where the result is either valid or an error based on the following criteria. I'm not sure if using Match, Lookup formulas will work for this problem.
Given
A B C
+-----------+-----------+----------
1 | IntRef | Value | Result
2 |-----------|-----------+----------
3 | r01 | Value 123 | Success (because B4 matches B3)
4 | r01 | Value 123 | Success (because B3 matches B4)
5 | r02 | Value ABC | Failed (because B6 differs from B5)
6 | r02 | Value XYZ | Failed (because B5 differs from B6)
Success Criteria
Scan each IntRef (A) column for all duplicate keys. Where they match
on a row check the Value column (B). Where all matching cells have
the same value set their result cell (C) to Success.
Failed Criteria
Scan each IntRef (A) column for all duplicate keys. Where they match
on a row check the Value column (B). Where all matching cells have a
different value set their result cell (C) to Failed.
I am sure there is a formula that can be entered into each cell of column C which will do a lookup for each IntRef cross referencing the contents of column B where the match occurs. This is going beyond Excel formula knowledge.
Is it possible to create and help formulate the calculation of the success/failed criteria (Column C)?
This appears to do the trick...
{=IF(COUNT(IF($B$3:$B$6=B3,IF($C$3:$C$6=C3,1)))=COUNTIF($B$3:$B$6,B3),"Success","Failed")}
Note that that's an array lookup formula (meaning you need to hit Ctrl+Shift+Enter when entering it).
This formula basically counts the number of times the A and B column values appear together and compares this to the number of times the A column value appears. If the two counts match, you have success.
Try this formula:
=IF(SUMPRODUCT(IF(A2=A$2:A$9,1,0),IF(B2=B$2:B$9,1,0))>1,"Success","Fail")
Assuming you have your data like this:
Formula is entered as Array Formula in C2 by pressing Ctrl+Shift+Enter.
Then just copy on the remaining cells.
I just added and changed the position of some data for testing.
Hope this works for you. Change the Range to suit your data size.

Excel Function Help - Compare 2 Cells in Worksheet to 2 Cells in another worksheet, if they match, return value from a different column

I'm wondering if someone would be able to offer some advice on the best way to do this please:
Data in Worksheet # 1
Col A | Col B | Col C
Part-1 | 8 | 2
Part-2 | 7 | 7
Part-7 | 9 | 4
Part-8 | 2 | 6
Data in Worksheet # 2
Col A | Col B | Col C
Part-1 | 8 | *Return value* (If Part-1 is found and 8 matches, return 2)
Part-2 | 7 | *Return value*
Part-3 | 8 | *Return value*
In Worksheet#2 in Cell C2 - I would like to check if the Part-1 in A1 is found in Col A in Worksheet#1. If it is, then I would also like to make sure the Number is B2 in Worksheet#2 matches the Qty in Col B next to the same part#, if both the Part# and Qty match, then i would like to copy across the value from the corresponding cell in Col C in Worksheet#1, to Col C in Worksheet#2. If it does not match, I would like it to return a 0.
Here is the a variation on Reinier's second approach in a form that will work in any version of Excel. You can use references to the specific data ranges, as I have done here, or to entire columns.
=SUM((A2=Sheet1!$A$2:$A$5)*(Sheet2!B2=Sheet1!$B$2:$B$5)*Sheet1!$C$2:$C$5)
This is an array formula, so it needs to be entered with the Control-Shift-Enter combination. It performs the same operation as the SUMPRODUCT. (There are several other ways to do this, such as using MATCH with INDEX or OFFSET.)
Essentially, what you are doing is a lookup based on values in two columns. Looking at it from that angle, you can use a the SUMPRODUCT function, which is supported in any version of Excel. Enter the following in Sheet2, cell C2:
=SUMPRODUCT((Sheet1!$A:$A=$A2)*(Sheet1!$B:$B=$B2)*Sheet1!$C:$C)
Select and drag down the right-bottom corner of C2 to complete column C.
This only works by virtue of the fact that the values in Sheet1, column C, are numbers. It breaks if value pairs in column A and B of Sheet1 occur multiple times, but you did not address that situation in your question in the first place.
For versions 2007 and up, you can use the more convenient function SUMIFS with basically the same approach:
=SUMIFS(Sheet1!$C:$C,Sheet1!$A:$A,$A1,Sheet1!$B:$B,$B1)
Alternatively, you can use a combination of IF and VLOOKUP functions. A formula that will work for Excel 2007 or newer is the following:
=IFERROR(IF(VLOOKUP($A1,Sheet1!$A:$C,2,FALSE)=$B1,VLOOKUP($A1,Sheet1!$A:$C,3,FALSE),0),0)
Older versions of Excel do not support IFERROR, but you can still use a similar approach as explained here.
I have uploaded an example workbook here, which includes an alternative method in column D of Sheet2 as well.

Resources