In excel, lets say I want to check if from A1 to A9 is equal to the value 10? How do I do it?
All I could think of is:
IF(A1:A9 = 10, "True", "False")
So what should I do to fix this?
Edit:
Since my question wasn't clear just now. I just want to know like...
IF(A1 = 10, True, False)
IF(A2 = 10, True, False)
IF(A3 = 10, True, False)
and so on...
For single cells to return TRUE or FALSE just type =A1=10 and drag down.
For your whole range at once, just try:
{=AND(EXACT(A1:A9;10))}
Notice it's an array formula entered through CtrlShiftEnter and will return TRUE or FALSE
You can test to see if any cell in A1:A9 contains a "10" using =CountIf():
=IF(COUNTIF(A1:A9, 10)>0, "True", "False")
If, instead, you wanted to know if the range summed to 10, you could stick Sum() in there (it's not clear from your question):
=IF(Sum(A1:A9)=10, "True", "False")
Not sure if you want all cells to be equal to 10, or any one cell to be equal, but here goes:
=IF(COUNTIF(A1:A9,10)=COUNT(A1:A9),TRUE,FALSE)
will show true if all values are 10.
This version will show if any one of the cells is equal to 10:
=IF(COUNTIF(A1:A9,10)>=1,TRUE,FALSE)
Checks whether the amount of cells equal to 10 are equal to amount of cells inside A1:A10
=IF(COUNTIF(A1:A9, 10) = ROWS(A1:A9), TRUE, FALSE)
Related
I have an excel formula that reads as follows:
=AND(A2 = 1, B2 = 2, C2 = 3)
This results in a FALSE value. I can use evaluate formula to understand which condition caused the AND to return a FALSE value. However, I want to display the column(s) that caused the AND to fail.
So in this case, lets say A2<>1 and B2<>2 which causes the criteria to return FALSE. I want to display this in a new column. So column D(for example) would display A,B.
Is there anyway to go about doing this without a macro? I racked my brains and could only come up with complicated nested IF statements to do this.
The TEXTJOIN function comes in handy here:
=TEXTJOIN(",", TRUE, IF(A2 <> 1, "A", ""), IF(B2 <> 2, "B", ""), IF(C2 <> 3, "C", ""))
This would generate a CSV list of the columns which did not match, and TEXTJOIN gracefully handles the separator as well as edge cases.
I have a spreadsheet that uses VBA to retrieve data from a database and copy it into a worksheet. I need to compare two columns to see if they match. The possible values are "TRUE", "FALSE", or a blank cell.
I have a simple formula to flag the row if the values are different: =IF(I2=J2,"Same","Difference")
This formula works fine if the values match, or if they are TRUE/Blank or TRUE/FALSE, but it does not evaluate as expected when there's a FALSE and a blank cell!
If I type in the word "FALSE" the formula evaluates properly (like in the image below). The formula only seems to be tripped up when the data is pasted from the database by VBA.
I suspect this has something to do with Excel treating FALSE and blank cells as both equivalent to "0", but I cannot figure out how to easily workaround this "feature." A couple things I tried:
I confirmed the cell types are set to "Text" for all cells and I tried using VBA to force the format to be text by using Range("I:J").NumberFormat = "#". Still evaluates to "Same."
I tried manually recalculating the formula by using the "Calculate Now" option in the Formulas ribbon. Still evaluates to "Same."
I can write an ugly formula in the IF statement to check if the cells match: =IF(OR(AND(I2="FALSE",J2="FALSE"), AND(I2="TRUE",J2="TRUE"), AND(I2="",J2="")),"Same","Difference") Is there a way to simplify this formula or force the I2=J2 formula to calculate correctly in case we ever have to handle data other than true/false/blank?
You can use EXACT:
=IF(EXACT(A1,B1),"Same","Different")
The reason is that it is defined as FALSE = 0 and TRUE = 1 (in formulas) or TRUE = -1 (in VBA).
If you compare A1=B1 you compare the values of these cells. And the value of FALSE is 0 exactly as the value of a blank cell is 0. So their value is equal and therefore they are considered the same.
In addition to only check if the values are the same A1=B1 also check if the data type is the same TYPE(A1)=TYPE(B1) using the TYPE function:
=IF(AND(A1=B1,TYPE(A1)=TYPE(B1)),"same","different")
This prevents implicit data type conversion (for example from a boolean FALSE to a integer 0 and vice versa).
TYPE() can distinguish between the following data types:
1 = Number
2 = Text
4 = Logical value (Boolean)
16 = Error value
64 = Array (Matrix)
128 = Compound data
When I put a set of formulas in excel 2013 like this:
A1 = abc
A2 = ac
A3 = bc
B1 = OR(TRUE) = TRUE
B2 = OR(FALSE) = FALSE
B3 = ISNUMBER(SEARCH({"a", "b"}, A1)) = TRUE
B4 = ISNUMBER(SEARCH({"a", "b"}, A2)) = TRUE
B5 = ISNUMBER(SEARCH({"a", "b"}, A3)) = FALSE
Yet if I add an OR function in the formulas :
C1 = OR(ISNUMBER(SEARCH({"a", "b"}, A1))) = TRUE
C2 = OR(ISNUMBER(SEARCH({"a", "b"}, A2))) = TRUE
C3 = OR(ISNUMBER(SEARCH({"a", "b"}, A3))) = TRUE
Logically the input reveived by the OR function in cell C3 is supposed to be FALSE (see B5 and compare it with B2) yet it resulted in TRUE when it supposed to result in FALSE. I want to know why is this happening? Is there an explanation for this? And does this happen in all version of excel after 2007?
Another interesting fact is that if I take the result in B5 as the direct input of an OR function like so:
C4 = OR(B5) = FALSE
It resulted in FALSE yet it is basically the same formula as C3. Why does this inconsistency happens? Is it a bug?
Updated question
According to the answers below, the OR function is an "array-friendly" function. What does that exactly mean? And how would a beginner like me know which function in excel are "array friendly" and which are not? Is there a list as such?
Also does this mean that the SEARCH and ISNUMBER function aren't "array friendly"? Yet it accepts "array" as an argument. I'm confused.
OR can take multiple arguments, or evaluate all items from an array...
ISNUMBER(SEARCH({"a","b"}, A3)) returns a single value in context of displaying formula result in a single cell, but it returns an array in array-friendly context such as inside OR (I don't know the exact name of this feature though.)
OR({FALSE, TRUE}) is TRUE, similar to OR(ISNUMBER(SEARCH("a", A3)), ISNUMBER(SEARCH("b", A3))).
Update after changing the question:
All of the intermediate functions must be array-friendly for this to work (I believe most functions are, but I am not aware of any list - you have to do some research yourself, this is not paid support).
The single cell output is NOT array friendly. When a result is an array, e.g. {TRUE, FALSE} and it's displayed in a single cell, only the first value will be visible in the cell.
More on array formulas where 1 formula can be inserted into multiple cells: https://support.office.com/en-us/article/create-an-array-formula-e43e12e0-afc6-4a12-bc7f-48361075954d
Using an excel formula to search if all cells in a range read "True", if not, then show "False"
For example:
A B C D
True True True True
True True FALSE True
I want a formula to read this range and show that in row 2, the was a "False" and since there are no falses in row 1 I want it to show "true."
Can anyone help me with this?
You can just AND the results together if they are stored as TRUE / FALSE values:
=AND(A1:D2)
Or if stored as text, use an array formula - enter the below and press Ctrl+Shift+Enter instead of Enter.
=AND(EXACT(A1:D2,"TRUE"))
As it appears you have the values as text, and not the numeric True/False, then you can use either COUNTIF or SUMPRODUCT
=IF(SUMPRODUCT(--(A2:D2="False")),"False","True")
=IF(COUNTIF(A3:D3,"False*"),"False","True")
=IF(COUNTIF(A1:D1,FALSE)>0,FALSE,TRUE)
(or you can specify any other range to look in)
=COUNTIFS(1:1,FALSE)=0
This will return TRUE or FALSE (Looks for FALSE, if count isn't 0 (all True) it will be false
I'm having some trouble with the below formula:
=IF(Data!X:X = 1,
IF(Data!H:H = "Horse",
IF(Data!U:U = A5, COUNT(Data!U:U)),0)
I need to check if column "X" in the excel sheet "Data" as the value of "1" if so, I need to check another column (in the same sheet) to see if it contains a particular text element(like: horse"), then I have to check to see if the column U in sheet "Data" contains the same value as my active sheet A5 if all the criteria match I need the count of how many times this occurs.
however my formula is only returning FALSE. I narrow it down to this part;
"IF(Data!H:H = "Horse")
now I double check , all the IF should end up as true.
Obviously I have something not right, any help would be great.
If you have Excel 2007 or later, you can use:
=COUNTIFs(Data!X:X, 1, Data!H:H, "Horse", Data!U:U , A5)
For Excel 2003:
=SUMPRODUCT((Data!X:X = 1)*(Data!H:H = "Horse")*(Data!U:U = A5))
Looks like the formula is incorrect (missing some of the false clauses in the if statements). This works for me:
=IF(Data!X:X = 1,
IF(Data!H:H = "Horse",
IF(Data!U:U = A5, COUNT(Data!U:U),0),0),0)