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
Related
Given that I have a range of cells (say A1:F1), in which all those cells contain either TRUE or FALSE. I know that I can write the formula =AND(A1:F1) in G1 which will "AND" across that range and return either TRUE or FALSE to G1.
My question is how would I do the something in VBA? Everything I find leads me to believe that I have to write code that looks something like
If A1 And B1 And C1 And D1 And E1 And F1 Then ...
But there must be a better way.
I've tried Var = And(A1:F1) and Var = Application.WorksheetFunction.And(A1:F1) both result in a line of red code.
I sure it's simple but I can't seem to find it.
I'm trying to do some stuff with solver but the results I need, I need to put the operators to the formula in another cell.
So, to be pratical, should be some like this:
A1 = <
A2 = >
A3 = <=
A4 = >=
B1 = 20
B2 = 30
C1 = =B1&A1&B2
The formula needs to understand the the data inside A1 to A4 are operators.
Any ideas?
Thanks!
As far as I'm aware, you can't do this in the traditional sense. What you can however do, is the following.
Select cell "C1"
Go to the formulas tab
Define a name
Name it something descriptive, like "Eval1" or whatever
Refer it to =EVALUATE(Sheet3!$A2&Sheet3!A$1&Sheet3!$B2)
Be aware that this uses relative selection, writing =Eval1 in cell G2 would not work in this case because it would try and evaluate A2 & E1 & B2 but can work if you adapt the refer to of eval1 in the name manager.
I need to fill a cell with the result of a user function. If the result of the function is different from zero, the cell should be simply filled with the result of the function; so far so good.
But if the result is zero I want the cell to be empty.
So I wrote this user defined function:
Function MyTestFunction(n As Integer) As Integer
Dim result As Integer
result = n * 2
If result = 0 Then
MyTestFunction = Empty
Else
MyTestFunction = result
End If
End Function
The function has no real purpose, it's just for investigating this issue.
The Excel sheet is like follows:
Cells A1 to A3 is just typed in data, cells B1 to B3 contain:
B1: =MyTestFunction(A1)
B2: =MyTestFunction(A2)
B3: =MyTestFunction(A3)
Now why does cell B3 display 0 instead of being empty ?
You have defined your function so as to always return an integer and so it does. An empty value is not an integer. You can modify your function as follows:
Function MyTestFunction(n As Integer) As Variant
Dim result As Integer
result = n * 2
If result = 0 Then
MyTestFunction = ""
Else
MyTestFunction = result
End If
End Function
You cannot return an Empty from any formula (with either builtin or user defined functions), see this.
"" is not the same as Empty, and they behave differently in many cases. A manifestation of the difference can be obtained by executing in the immediate window the line below, on both a selected empty cell and a cell containing ""
? TypeName(Selection.Value)
The most useful substitute for Empty as the result of a formula depends on your use of the cell containing the formula, see this for a taste of it.
Still in the ToDo list of MS (or perhaps not...)
EDIT:
I found the following relevant question (it is worth checking the answers)
Return empty cell from formula in Excel
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)
Been looking around and can't find anything for it. I am still very new to all this so I apologize if its a simple solution.
This is an example of what I was trying to do:
=IF(E4=True,0,=I16)
Where E4 is a list of names and I16 is the sum of a set of items.
What I want is if E4 = True then show value of I16 , if not show 0
All my calculations are done elsewhere this is just a summary that I want the option to either turn on or off by changing the value of E4 from true to false.
Hopefully I explained it well.
the syntax of the excel if statement is =IF(LOGICAL_TEST,[value if true],[value if false]) so there is no need for another = within the syntax.
You will need " around anything you want as text in the form of:
=IF(A1 = "Bob","Robert","Not Bob")
but to show values of other cells you simply need the cell name:
=IF(A1=32,b1,c1)
If you want to nest the logic with another if statement you place the IF(logic,[true],[false]) within the true or false location as such:
=IF(A1 = 5,IF(b2>a1,b1,"less than"),c1)