I wonder if anyone can help with this:
I have a sheet with rows of data. Within each row there will be a single occurrence of either 'x' or 'y', among many other entries in other columns. The string is the only text in the cell.
No row has both 'x' and 'y'.
I'd like to identify 'x' or 'y' in each row and copy the value to a new column.
In layman's terms something like;
IF row contains "x" write "x"
else If row contains "y" write "y"
else write ""
end
I have managed to get some kind of multi step process going where I use the formula below. But it is super clunky and requires many steps, copy, pasting, results etc and won't fly for the guy on Monday.
=IF(ISNUMBER(SEARCH(substring,text)), "x", "y")
Many thx
D
You can do nested IF statements. You didn't specify where you want the formula in relation to the data, but if you wanted the result in column A then you could do something like this (assuming you want the result in cell A1 and looking at data in cells in range B1:IV1)...
=IF(NOT(ISERROR(MATCH("y",$B1:$IV1,0))),"y",IF(NOT(ISERROR(MATCH("x",$B1:$IV1,0))),"x",""))
The basis of this is the MATCH() function. When a match is NOT found in the range, it returns a #NA error, otherwise it returns the location index of where the first match is. Since it throws an error when it doesn't find a match, I've wrapped the MATCH in the ISERROR function to turn it into a TRUE/FALSE boolean where TRUE is returned when it is an error and FALSE returned when it's not an error. Since that TRUE/FALSE is opposite of what you're looking for, I wrapped that in the NOT() function to reverse it...returning TRUE when it finds the match of either 'x' or 'y'.
Related
I'm running an excel formula and having issues with a #Spill error. The idea is that I have a column of cells that contain a ton of different numbers. I have another column with a bunch of String values that contain numbers as well.
For example,
Col A
Col B
1
String.10
2
String.1
3
String.3
4
String.6
The output, after running the formula, should return records of:
String.1
String.3
as 1 and 3 are contained in a cell.
The formula:
=IF(ISNUMBER(SEARCH($A$2:$A$10,B2)), "Yes", "No")
The idea is that I have a static range of cells to compare to and a way longer list of String.'numbers'. Why would this function result in a spill error?
Although this seems to be a trivial task, there are some pitfalls that need to be taken into account. For example, the problem that the search for "1" will be TRUE for both String.10 and String.1.
One approach to solving this issue in one formula could be as follows, combining, in particular, the following functions: TEXTJOIN(), BYROW(), and FILTER(). I also use some other functions that come in handy to find the exact string, etc.
Assuming that the data is stored in the range A2:B5, you can enter the following formula in C2, for example:
=TEXTJOIN(";",TRUE,
BYROW(A2:A5,LAMBDA(rowN,
FILTER($B$2:$B$5,
EXACT(rowN,RIGHT($B$2:$B$5,LEN($B$2:$B$5)-SEARCH(".",$B$2:$B$5)))=TRUE,""))))
The output of this formula looks as follows: String.1; String.3.
The TEXTJOIN() function combines the output of the BYROW() function separated by e.g, ";". In the BYROW() function, you first specify the array to which you want to apply the function specified in the LAMBDA()statement. In this context, rowN is then in the following simply used as the name for this particular array. The FILTER() function is used to filter data from a specified range that meets a certain criterion. The criterion in this context is that the number (specified in column A) matches the numeric part of the string in column B. To extract only the numeric part of the string, the number after the "." is extracted by combining the RIGHT(), LEN(), and SEARCH() functions. Subsequently, it is important to use the EXACT() function to ensure that when searching for "1", only this particular row is recognized as TRUE and not also the number "10", which also contains a 1.
Variation of the specification to get the output in a different format:
If you do not want the strings combined, you can simply delete the TEXTJOIN() function, which will return the corresponding string or an empty cell:
=BYROW(A2:A5,LAMBDA(rowN,FILTER($B$2:$B$5,EXACT(rowN,RIGHT($B$2:$B$5,LEN($B$2:$B$5)-SEARCH(".",$B$2:$B$5)))=TRUE,"")))
If you want to return "Yes" or "No", you can put the formula into an additional IF() statement as follows:
=IF(BYROW(A2:A5,LAMBDA(rowN,FILTER($B$2:$B$5,EXACT(rowN,RIGHT($B$2:$B$5,LEN($B$2:$B$5)-SEARCH(".",$B$2:$B$5)))=TRUE,"")))<>"","Yes","No")
In addition, I give some flavor for the spill error. This occurs because you are looking for a specific string in an array of values. Therefore, the output returns "Yes" and "No" for each row. In your particular case (the formula you presented above), an array containing 9 times "Yes" or "No" will be returned. Thus, if you then copy the formula down, you will get the spill error because you have stored something in the row and it is not possible to spill the 9 values down.
=BYROW($B$2:$B$5,LAMBDA(B,ISNUMBER(XMATCH(--(INDEX(TEXTSPLIT(B,".",,),2)),$A$2:$A$10))))
This will spill results (TRUE/FALSE) for all values.
It splits the text in column B and shows the string after the .. It's then converted from text to number by using --() and that value is matched with the values in column A. If it matches it returns the row number, so ISNUMBER is TRUE.
If no match is found, it throws an error, which is not a number, so ISNUMBER is FALSE.
Using LET will make it easier to update the ranges Col_A and/or Col_B. (You may even want to use a FILTER for Col_B: Col_B,DROP(FILTER(B:B,B:B<>""),1)) :
=LET(
Col_A,A2:A10,
Col_B,B2:B5,
BYROW(Col_B,LAMBDA(B,
ISNUMBER(
XMATCH(--(INDEX(TEXTSPLIT(B,".",,),2)),
Col_A)))))
I want to concatenate the value of two columns in the current sheet and then result should be compared with the concatenation of two column value in another sheet.
e.g - The entered value in Column W and X in current sheet after concatenation should be compared with the existing value in column Y and column Z(after concat) of another sheet.
I have tried using the formula COUNTIF(Sheet2!CONCAT($W$2,$X$2:$Y$2,$Z$2),A2)>0 and some different alteration in this but it seems COUNTIF has range and criteria as argument and this is string which is causing error.
If you want to compare, a simple '=' will do.
Concatenation can be done using '&'.
in current sheet:
=W1&X1=Sheet2!Y1&Sheet2!Z1
will return TRUE if both concatenations are equal and FALSE if they are not.
To find the value W1&X1 in the entire range, I suggest you use a help column (unless you are willing to write a macro). In the help column of sheet1, you concatenate the values (=W1&X1 - drag down). In the hlep column of sheet2 you do the same. Then you make an additional column to check for matches, by using
=match(ValueHelpColSheet1,HelpColSheet2,0)
This formula returns the row number in which the match is found and an error when the corresponding value is not found. You can replace this error with something else using IFERROR if you want to.
I need to compare two columns I and L and copy matched result from M column. It is a list of 1000+ product codes (I,L) and EAN codes (M). So if cell I1 is found in range of L1:L1000 (lets say it found in L3 cell), then formula should copy the M3 cell.
Tried VLOOKUP and MATCH and some IF, but cannot figure it out how to make it work as it returns blank or REF! or N/A or errors-out completely. I'm desperate and don't know what i'm doing wrong...
=VLOOKUP(I1:I1164,L1:L1164,13,FALSE)
and with
=IF(ISNUMBER(SEARCH(I1,L1:L1000),M1," "")
Result should be in N column.
When using VLOOKUP, you need the lookup range to include both the range of values you're looking for (which MUST to be the first column) and the return values (whose column you specify as relative to the range. So in your case, you'll be looking up in L1:M1164 and using column 2 as return results (since column M is the second of L1:M1164).
Also, the value you're looking for will probably be just an item, relative to the current line. I'd thus try it that way (in N1):
=VLOOKUP(I1;$L$1:$M$1164;2;FALSE)
Wrapping it up in an IFERROR as suggested in SJR's answer might be a good idea too.
Try this
=iferror(index(m1:m1000,match(i1,l1:l1000,0)),"")
The match bit returns 3, the index bit then looks for the 3rd value in column M; the Iferror returns an empty string in the event of an error (i1 is not found).
In a sorted list, I'm trying to find all values in 'B' for each person in 'A' and display them as shown in column 'D'. I've gotten as far as what I have in column 'F' and I know how to concatenate the values if I had them but I'm stuck. How can I find all the values in 'B' that correspond to 'A'? (without vba)
https://imgur.com/a/hICdzwX
I'm new to excel so I'm sorry if this doesn't make sense.
Pretty sure this is what you're looking for:
IF(A5=A4,"",TEXTJOIN("-",FALSE,(B5:INDIRECT("B"&(ROW()-1+COUNTIF(A:A,A5))))))
(I hope the picture uploaded :-)
#Jeeped was correct in using textjoin(), which I wasn't familiar with, but you're primary criteria was for (essentially) matching rows. Conventional thought is to loop through matching names, but loops = VBA, which you want to avoid. So, the alternative is knowing the length of the list.
Breaking down the formula:
IF(A5=A4, # because the list is sorted, we display where name rows are different
"", # otherwise just return a blank
TEXTJOIN( # (thanks #Jeeped -- this made the work a lot easier)
"-", # your list delimiter
FALSE, # False (include) True(ignore empty cells -- your call
(B5: # use the range - starting from the current 'B' Cell (note same row as (A5) through...
INDIRECT("B"&(ROW()-1+COUNTIF(A:A,A5))))))
Indirect says: pass the 'created value' as if an entered reference, but in this case, the 'number of cell {down}' is determined by the countif(), that is 'how many of the keys' are in the list. The number is overstated by (+1) because were already sitting on the starting row, therefore (-1). So, this parameter starts with "B5:" and appends (as an indirect()), the current row as a number MINUS 1 PLUS the total count() of cells in column A that matches the value of column A in the current row, EG: ROW=5, Count = 2, => 'B5:B'+(5-1+2)
returns: 'B5:B7' to the TextJoin().
Screen shot of Formula & results...
I am trying take an ID in ColumnX and verify find an occurrence of this ID in columnY using the MATCH() function. This function returns a row number of the match. I now need to take the row number and combine it with a ColumnZ in order to make a reference to a value where I later run a comparison on this value.
Here is the code I have so far:
IF(EXACT(MATCH(X:X, Y:Y, 0), Z:Z), "Y", "N")
The bug in this code is where I am passing the parameters into the EXACT function. It wants two strings (i.e. cell values), only the Z:Z statement correctly satisfies this, is there anyway to achieve something like this:
IF(EXACT(("Z" + MATCH(X:X, Y:Y, 0)), Z:Z), "Y", "N")
I am simply trying to create a cell reference from a known Column number (what I don't know how to do) and an unknown row number (produced by the MATCH function).
I have already tried using the Vlookup function and it does not produce the desired results.
Have you tried to use INDIRECT?
I believe that's the function you might need. You'll need to check now where you need to add it. I'd guess it's here:
=IF(EXACT(INDIRECT("Z" & MATCH(X:X, Y:Y, 0)), Z:Z), "Y", "N")
Rgds
Mike,
If I understand your needs, the following will work. It says, "find the row in column Y that matches the value in X1 and return the value at that row in column Z":
=INDEX(Z:Z,MATCH(X1,Y:Y,0))
The 0 argument in the Match function specifies an exact match, meaning that column Y doesn't need to be sorted (similar to the optional False argument in VLookup).