I have a column of codes and I specifically want to extract ANY of these codes with Excel's IF function.
I wrote this code and it did not work: =IF(OR(O2={"6122";"6124";"6200";"6197"});1;0)
How can I use the IF function or other function to pick out any of the above codes?
EDIT: the code itself works but it does not return 1 when it hits any of the specified codes.
Check the value in cell O2. If it is text, then your formula will work. If the value in cell O2 is a number like 6122, then your formula will not work, since it is explicitly looking for a text value of "6122" and the other text values.
Data type matters. The text "6122" is not the same as the numeric value 6122.
You can alleviate the issue by coercing the value in O2 to a number and forcing a numeric comparison with
=IF(OR(O2+0={6122,6124,6200,6197}),1,0)
(if your regional settings use the semicolon ; as a list separator, please replace the commas in the above formula with semicolons)
This will work if O2 is either text or numeric. The values to compare with are numbers.
So, determine what data type is stored in cell O2 and make sure that you compare it with a suitable data type in your formula.
Related
I have in a cell two numbers "=5+4" as a text. This is a result of another operation.
I took a part of another formula and concatenated it with "equal" symbol:
= "=" & RIGHT(FORMULATEXT(V8);LEN(FORMULATEXT(V8))-SEARCH("+"; FORMULATEXT(V8)))
I want to get the result of 5+4 in a cell- which means "9" ;)
I DO NOT WANT TO USE VBA code.
my initial problem was to extract all numbers except the first one from an equation and sum in another cell: A1: "=6+5+4". A2: "9". Maybe it can be solved without VBA?
You could try (assuming only addition):
Formula in B1:
=SUM(FILTERXML("<t><s>"&SUBSTITUTE(MID(A1,2,LEN(A1)),"+","</s><s>")&"</s></t>","//s[position()>1]"))
In fact, if you don't want to use the 1st number we could also discard taking '=' into account:
=SUM(FILTERXML("<t><s>"&SUBSTITUTE(A1,"+","</s><s>")&"</s></t>","//s[position()>1]"))
And since SUM() will ignore text in the final answer, we can now even further simplify this (thanks #JosWoolley):
=SUM(FILTERXML("<t><s>"&SUBSTITUTE(A1,"+","</s><s>")&"</s></t>","//s"))
If you are always adding 2 numbers, then you can use this:
=VALUE(VALUE(MID(A1;2;SEARCH("+";A1)-2))+VALUE(MID(A1;SEARCH("+";A1)+1;9999)))
My column A is formatted as text, and all values follow same pattern: =Value1+Value2
So the formula extracts Value1 and Value2 as text with MID functions, based on the position of + symbol. Then Excel convert both values into numeric with VALUE function. Notice there are 3 values, the third one is to make sure the cell stays at standar format (in some versions of Excel, like mine 2007, when involving text formatted cells into formulas, the formulated cell autoformat itself to text format, making the formula to work just once).
As you can see in the image, it works perfectly but this is just for pattern =Value1+Value2. For different patters you'll need different formulas.
If you want to make a formula to work with all patterns, then indeed you need VBA.
I have two columns in my excel, Date 1 in A and Date 2 in B. I'm trying to find the number of times Column B is greater than Column A. I'm using the formula =SUMPRODUCT(((B2:B5-$A$2:$A$5)>0)*1) and receiving an error. The error is due to the data in Column B is being pulled in from a formula, where my value_if_false is "". While the cell is blank, Excel sees this as data and will not execute my original formula.
If I go to B4 and delete the value, my original SUMPRODUCT will execute. I'd like not have to go back and do that. I've tried =SUMPRODUCT((NOT(ISBLANK(B2:B5-$A$2:$A$5)>0))*1) but it's returning 0. Any suggestions?
Try following array formula:
{=SUMPRODUCT((IF(IFERROR(VALUE(B2:B5);FALSE); B2:B5;0)>$A$2:$A$5)*1)}
Array formula after editing is confirmed by pressing ctrl + shift + enter
Writing "" (nul string) to a cell that is supposed to contain a number (such as a date) is never a good idea because it leads to problems like this one. The solution is in not writing a string (text) to a numeric field. Write zero instead, and then deal with the display of zeros via global settings or cell formatting.
Of course, any date would be greater than zero. If this leads to the wrong count the obvious remedy would be to make a second count of instances where zero is involved and deduct the result of the second count from the first, like, SUMPRODUCT(1)-SUMPRODUCT(2)
I guess if you wanted to stick with SUMPRODUCT and avoid array entry, you could try
=SUMPRODUCT((B2:B5<>"")*(B2:B5>A2:A5))
or to exclude anything except a number (which in this case would be formatted as a date)
=SUMPRODUCT(ISNUMBER(B2:B5)*(B2:B5>A2:A5))
is possibly better.
B4 contains "", not ="".
Probably very simple to do, but can't figure a way to do it.
Trying to find a way of getting the power value of a cell that is written in scientific notation (i.e. 1*10^x).
An example would be:
Cell value: 1.39E+04, or 1.94E-12
Value needing to be extracted: +04, -12
Need to do it using either the formulae or functions of Excel, no VBA.
Put a number in A1 and in B1 enter:
=RIGHT(TEXT(A1,"0.00E+00"),3)
It does not matter if A1 format is Scientific or not:
NOTE:
This method avoids using any LOG() functions.This method should work on any numeric value (not text).This method should work regardless of how the numeric value is formatted.
Assuming data is in cell D7:
=RIGHT(TEXT(D7,"#"),LEN(TEXT(D7,"#"))-FIND("E",TEXT(D7,"#")))
How can I verify partial strings in cells across columns without having to look for an exact match?
I have a single spreadsheet with two columns that contain corresponding pairs of data in the form of text, or "strings". However, each corresponding pair almost matches except for a couple characters on the end. I need to make excel recognize the pairs despite the inexact string match, and return a "yes" or a "no" as to whether or not there a corresponding pair exists between the two columns. I want it to tell me "yes" or "no" in a single cell.
I do not want to delete characters from either column to make them match, they have to stay as they are.
My solution was that if I used an IF statement to determine whether A:A=B:B, all I would need to do is tell excel to also substitute the conflicting text characters with empty spaces, but that didn't work :( It returns #VALUE instead of a yes or no. I placed the function inside D1.
This is my formula:
=IF(SUBSTITUTE(A:A,"-Z","")*A:A=B:B,"Yes","No")
I think maybe I need a formula that will accomplish the following:
If a string with a length of up to 12 characters in a cell of column A matches another string in a cell of column B, return "true" in C2
I don't know what formula that would be. I would appreciate any help! Thanks in advance!
You can use this formula =IF(SUMPRODUCT(--(LEFT($A$2:$A$23,12)=LEFT(B2,12)))>0,"TRUE","FALSE"). It will first extract first 12 characters from strings in column A, then compare it to the first 12 characters in column B. Adjust range to your needs.
You can use VLOOKUP construct like below in cell C2 and then copy down:
=IF(ISNA(VLOOKUP(LEFT(A2,12)&"*",B:B,1,0)),"NO","YES")
I have read http://poi.apache.org/spreadsheet/eval.html but I dont get it to work ...
I have a column in my sheet that contains these values:
D+1 (pseudo-formula, to be evaluated in java)
01.01.0001 (string constant)
=A1 (formula where A1 contains pseudo formula 'D+2')
=A2 (formula where A2 contains '13.08.2013')
(For strings like "D+1" I have written a parser that replaces D by todays date and increments it by one. "01.01.0001" is a magic value. "=A3" is obviously an excel formula )
How can I safely get all these values to a plain old java string that
dereferences excel formulas before
leaves pseudo formulas intact
treats everything else as string
???
so for above example I want to get:
"D+1"
"01.01.0001"
"D+2"
"13.08.2013"
If you're doing it by hand: You need to check both getCellType() and getCachedFormulaResultType(). The type will let you work out what kind of cell it is, for formatting / cell value fetching etc. For formulas, when you see it's a formula cell, you can then fetch the last evaluated value and the type of that
However, based on what you want, I think there might be a much simpler way to go. I think you can probably use DataFormatter, specifically formatCellValue(Cell)
If you use DataFormatter, it'll identify the type (including formulas), fetch the value, fetch the Excel-applied number/date formatting rules, and apply those. You get back a String which is the closest Apache POI can manage to what's shown in Excel, which looks like what you want