I was using IF statement to group some numbers together.
In column A I have numeric and text values.
A B
1 s =IF(A1>200,2345,"ad")
If I do this then the B1 returns 2345.
How does Excel compare string values with number values?
For the Excel compare operators (e.g. <, =, >), number values are less than text values which are less than logical values. You can use the VALUE function to convert text values to number values for number comparisons. You can use the TEXT function to convert number values to text values for text comparison.
You can concatenate a letter to both the formula (string) and the number and excel will be able to compare them. I was having the same problem when comparing the result of an index match formula with a number and this solved it easily.
Example:
String:
=CONCATENATE("Q",Result from formula)
Number:
=CONCATENATE("Q",Number)
IF string=number should work now.
Related
In xls I have a single cell with multiple arguments in text format like this:
a;c;d;b
I want a formula which tells me the order, so for Input
a it should return 3
c it should return 2
d it should return 1
b it should return 0
the substrings "a", "b" etc. have multiple letters.
First of all take the string value of the cell, then split it based on the semicolons. After that you have an array (or a list) of strings.
Then sort this list as you need.
I cannot figure out your sort order - it looks like you made it up.
So maybe you just need to assemble the strings from the list in your order, but that is what string concatenation should solve.
You can try the following on cell D2:
=LET(split, TEXTSPLIT($A$1,";"), cols, COLUMNS(split),
pos, SEQUENCE(1, cols, cols-1,-1), XLOOKUP(C2:C5, split, pos))
Here is the output:
where the Lookup column have the input values for testing purpose. If you enter a letter that doesn't exist in cell A1, it returns #N/A.
Explanation
LET function is used to avoid repetitions of the same calculations in the formula.
From your requirement it seems you want to return the position in reverse order starting from the number of letters minus 1 and ending in 0.
split variable TEXTSPLIT($A$1,";") generates the following output (column wise):
a c d b
The cols variable COLUMNS(split) calculates the number of columns of the split array. In our case 4.
The pos variable represents the array positions and the output we are looking for, SEQUENCE(1, cols, cols-1,-1) would generate the following output:
3 2 1 0
and XLOOKUP(C2:C5, split, pos) generates the final result.
Notes
If you don't have TEXTSPLIT available in your excel version, you can try instead:
=FILTERXML("<t><s>"&SUBSTITUTE(A1,";","</s><s>")&"</s></t>","//s")
Remember FILTERXML has also some constraints: it is not available in Excel for the web and Excel for Mac. Since the solution generates column-wise arrays, you need to transpose the output of FILTERXML, i.e. TRANSPOSE(FILTERXML(...)).
An alternative if you can't use FILTERXML is the following one. Adapted the response of the question: Split a string (cell) in Excel without VBA (e.g. for array formula) provided by: #Carble:
=LET(txt,A1,del, ";",length, LEN(txt)+1,
items, length-LEN(SUBSTITUTE(txt,";","")),
seq, SEQUENCE(items,,0), findSpaces, FIND(" ",SUBSTITUTE(txt,del," ",seq)),
startTxt, IFERROR(findSpaces+1,1),startDel1, IFERROR(findSpaces,0),
startDel2, IFERROR(FIND(" ",SUBSTITUTE(txt,del," ",seq+1)), length),
MID(txt,startTxt,startDel2-startDel1-1)
)
If your version doesn't allow to use LET, then just replace the value of the variable defined in the formula. It will require SEQUENCE (available from O365 2021). Not having even SEQUENCE will make it very hard. A helper columns will be required to generate the sequences.
I need help with an Excel formula. I have to find the cell value based on a comma separated value list in another cell
For e.g Here G5 will have the max of Estimated End Date column (H) whose ID column contains values 1 or 2 (comma separated list in E5). Again above is e.g. there could be more than 2 values in the list
so G5 here should be 09/03/22 since it is max of 04/03/22 and 09/03/22.
We normally only respond to questions that include code or formulas we can work from (it's probably why you've received a downvote). However, in this case, I can see how you wouldn't know where to start.
Assuming you have Excel 365, the steps are:
Convert CSV to array
Map the array to found row numbers
Grab the max of the resultant array
I don't have the TEXT_SPLIT function, so I have to roll my own. I have a few helper functions for this (note these are saved as Names, in Formula->Define Name, so you'll need to add them).:
csvText
=LAMBDA(txt,"," & txt & ",")
csvCount
=LAMBDA(txt,LEN(txt)-LEN(SUBSTITUTE(txt,",",""))-1)
csvPosOf
=LAMBDA(n,txt,FIND("#",SUBSTITUTE(txt,",","#",n)))
csvLenOf
=LAMBDA(n,txt,csvPosOf(n+1,txt)-csvPosOf(n,txt)-1)
csvArray
=LAMBDA(txt,MAKEARRAY(1,csvCount(txt),LAMBDA(r,c,TRIM(MID(txt,csvPosOf(c,txt)+1,csvLenOf(c,txt))))))
This covers the splitting of your csv text to an array.
The mapping of the IDs to row numbers and MAX call is simply this formula:
=MAX(MAP(csvArray(csvText(C3)),LAMBDA(v,INDEX($A:$H,MATCH(VALUE(v),$A:$A,0),8))))
You'd add this formula into each row of your G column. Again, adjust the cell references as you need them. Please note you must call the VALUE function on the LAMBDA expression, as you can't implicitly MATCH a text representation of a number to an actual number.
I have a bunch of time data that's formated weirdly, ranging from numbers 100 (representing 1 AM, or 01.00.00) to 2359 (representing 11.59PM, or 23.59.00).
I have been trying to use the TIMEVALUE() function to convert these data, but it just returns #Value?, I guess because the time format 'HHMM' is not recognized without the ' : ' separating them?
What I'd like is to convert it to the HH:MM:SS format, where the SS would automatically be zero.
Use REPLACE:
=--REPLACE(A1,LEN(A1)-1,0,":")
Then format it as desired.
If your text values are consistent, this can be carried out by using a formula that splits the value by the number of characters and then recombines the split values into a time value.
All formulas assume that your weirdly formatted text value is in cell B2
=IF(LEN(B2)>3,LEFT(B2,2),LEFT(B2,1))
This formula works out the first (hour) element of a time, if the text string is greater than three characters it will take the first 2 characters of the string (23), if its less than 3 characters it will only take the first character (1)
=RIGHT(B2,2)
This formula takes the second (minute) element of the time.
=TIME(C2,D2,0)
Finally this formula converts the two text elements into a string
C2 = The cell with formula 1 in it
D2 = The cell with formula 2 in it
This could all be written as the following formula if needed
=TIME(IF(LEN(B2)>3,LEFT(B2,2),LEFT(B2,1)),RIGHT(B2,2),0)
We need to count how many occurrences of each number are in a cell over a range of cells in the same column and output a tally of the totals for each number. See the attached picture and the desired output in the column next to it. We tried other formulas found online in both excel and open office with no results.
letter Count
Working Count
Try the following formula in D1:
=LEN(TEXTJOIN("",TRUE,A:A,"#"))-LEN(SUBSTITUTE(TEXTJOIN("",TRUE,A:A,"#"),C1,""))
and populate down.
(you will need 2016 or later for TEXTJOIN)
Option 1
Single array formula (ctrl+shift+enter !) which will work for strings with a maximum length of [5] alphanumeric characters (but you can easily modify the formula by adding a few numbers in the hard-coded array constant {1,2,3,4,5}):
{=SUM(N(MID($A$1:$A$500,{1,2,3,4,5},1)=TEXT(C3,"#")))}
You can add some further trickery to let Excel define the array constant, so the formula will work for any length of the string of digits :
{=SUM(N(MID($A$1:$A$500,
COLUMN(INDIRECT("A1:"&CHAR(65+MAX(LEN($A$1:$A$500)))&"1"))
,1)=TEXT(C3,"#")))}
The part in the middle (COLUMN()) creates the {1,2,3,4,5} array. You might have seen other versions of this formula, without the CHAR, which I use to create a reference to e.g. cell E1 (knowing that 65 is the code for "A").
.
Option 2
This array formula (ctrl+shift+enter !) works in all Excel versions, but is not very "elegant" as you have to repeat the key part of the formula as many times as the maximum digits you have in your cells (this example is for max 3 characters):
{=SUM(
N(MID($A$1:$A$500;1;1)=TEXT(C3;"#"))+
N(MID($A$1:$A$500;2;1)=TEXT(C3;"#"))+
N(MID($A$1:$A$500;3;1)=TEXT(C3;"#")) )}
The character you are counting is in C3. This will work for numbers and letters. If you can have five alphanumeric characters, you have to add two more N(...) parts, and replace the second parameter of the MID function with 4 and 5 respectively.
I have a spreadsheet used to verify a long list of 8-digit hexadecimal numbers for duplicates.
It has two columns - one for the hexadecimal values and another where the following formula is used to check for duplicates (given that this second column is column B):
=COUNTIF($B:$B, B1)
This has worked fine for most numbers except for these values:
69000700 and 690007E2.
The first column is formatted as text, however it seems that the COUNTIF function is doing some kind of unwanted implicit cast of my hex value, and taking the second hex value as an exponent (which would make it the same as the first value).
It also doesn't seem to matter what format my hex column is - the COUNTIF function always interprets these values as numbers and therefore they appear as duplicates.
Is there a way to ensure the COUNTIF function takes these cell values as string parameters without doing an implicit cast?
Maybe it's feasible to add an extra column with a formula
=CHAR(34) & B1 & CHAR(34)
copied down.
The formula encloses the text into quotes, and "690007E2" will no longer be interpreted as "69000700" (Excel 2003).