sorry if this has already been asked, have read many answers about this, (this is the one that best describes my situation - Excel - Match cells that contains exact match from list )
I would like Excel to index a column where the cells contain comma separated lists of values. Some lists have only one entry and thus no comma.
I would like Excel to find an exact match for a given string, for example, if I search for "C2" I would like it only to find "C2" and not "C22" or "C230". It should also find "C2,"
I have got this to work for single cells with this formula :
=ISNUMBER(FIND(" "&E$1&", "; " "&$B1&", "))
Where "C2" is contained in cell E1 and the comma separated list is in cell B1.
However, if I try to incorporate this into an INDEX formula (I would like it to return the corresponding value from the cell in column A where C2 exists), it once again finds all instances of "C2". I wrote the formula as follows :
=INDEX(A:A;ISNUMBER(FIND(" "&E$1&", "; " "&B:B&", ")))
If anyone has any advice on how to get this to work, I would be most grateful!
Katrina
Use the =ISNUMBER(FIND(" "&E$1&", "; " "&$B1&", "))function in an auxiliary column, say F, and pull it down along the comma-separated values in B.
Use =INDEX(A:A;MATCH(TRUE;F:F;0)). This will find the first occurrence of C2 or #NV in cases where C2 does not occur.
Note that the function will find "C2" and "C2, " but not "C2,".
=SUMPRODUCT(ISNUMBER(FIND(" "&E$1&", "; " "&B:B&", "))*A:A)
SUMPRODUCT works great with arrays. The ISNUMBER function returns an array of false/0 and true/1 that is then multiplied with the respective value in column A, returning only that value in A where ISNUMBER is true. If there are several occurrences of the E1 value, the sum of the respective values in A is returned.
For better performance the ranges in A and B should be restricted to those where values are possible, say A1:A100 and B1:B100.
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)))))
This is the problem i am facing in Excel formula
enter image description here
In column F, i want to find the common text across A2 to E2 (containing Blanks)
My Question:
Is there a simple way to get the result without VB?
Any help is appreciated,thanks
I found that google sheets has some really cool functions.
If you put the formula =SPLIT(A1, ",", TRUE,FALSE) in the cell after your row of common text (or probably even in a different sheet - "probably because hadn't tried it, though it should), the next x cells (where x is the number of "," in A1 - because "," is the delimitator) will be the text.
then you can put the code =IF(SUM(ARRAYFORMULA(if(REGEXMATCH($A$1:$D$1,F1),1,0)))=COUNTA($A$1:$D$1),F1,"") into an equal number of cells after that (probably should just put into the max number), and =CONCATENATE(I1:L1) into the last cell.
Ok. So to tweak this for yourself: I found that ARRAYFORMULA lets you put an array in place of a single cell in a function inside. how it exactly works I read its like a for loop. but I can't really vouch for that. but here it lets you have REGEXMATCH (which is a Boolean check on the cell you give it for if it contains the given REGEX) check each cell in the array.
the sum will add them up, and the if will match against the COUNTA to find if the number of cells in the array that contain this string is equal to the number of non-empty cells.
the concatenate at the end adds all the cells (containing the regex function) together, and since the only non-empty cells will be the one with the string, that is what this cell will return (no spaces).
code:
results:
the test data:
If you need in specifically Excel... this won't help.
We can use power query to achieve the desired result.
Unpivot the columns in Power query
Split all the columns by Comma delimiter
Create a custom column to see if the first column records exist in the remaining columns.
Use the functionText.contains.
Sample function: =Text.Contains([column.1],[column.1]&[column.2]&[column.3])
If the above function returns TRUE then get the first column result(This is the expected result) and load the data back to your excel
Is there a way to extract multiple strings between specific characters in excel and separating them with a comma.
For example:
I am thankful for every help!
The following requires a version of Excel O365 that supports dynamic arrays and the LET function.
If I understand correctly you are looking for something like this.
This formula will list all the positions of all [ in the string using dynamic array functions.
=LET(x,$B$2,
y, SEQUENCE(LEN(x)),
raw, IF(MID(x,y,1)="[",y,""),
filtered, FILTER(raw,raw<>"",""),
filtered)
LET allows you to set names within a formula using parameter pairs. The first is the name; the second is the value of the name. The last parameter is the value returned. In this case, x is set to cell B2. y is set to the array listing the numbers from 1 to the length of x using the dynamic array function SEQUENCE. raw is a list that shows the value of y if that position is [, otherwise it is blank. filtered uses the FILTER function to remove all of the blank rows. filtered is the last argument of the LET function so that is what is returned. If this formula is entered into cell A4 then A4 will show 1, A5 will show 14 and A6 will show 28.
If you then enter a similar formula in B4 replacing [ with ] then the result is {7,21,35} in cells B4, B5 and B6.
Finally, in cell B2 you can enter =TEXTJOIN(", ",TRUE,MID(A2,A4#+1,B4#-A4#-1)). This will return the result you are looking for.
If you are unfamiliar with dynamic arrays, A4# indicates an entire dynamic array starting in cell A4. In this case, it is the same as A4:A6.
More information on Dynamic Arrays
More information on LET
You can't do it with only formulas in Excel 2007. You need VBA UDF then. With Excel O365 having dynamic formula access, this can be done like:
=TEXTJOIN(", ",TRUE,TRIM(LEFT(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A1,"]",REPT(" ",100)),"[","</s><s> ")&"</s></t>","//s[starts-with(., ' ')]"),100)))
Considering that you are using too old version of excel which lacks dynamic array functions and besides too many other useful functions, You may probably have to do a long workaround here.
First using substitute and len You have to find out number of such square parenthesis in each of the row. Thereafter you have to work out the formula of max of such numbers.
Do it like this
Assuming your text-values in A2 for a max of 4 occurrences enter the following formula in B2
=SUBSTITUTE(TRIM(REPLACE(LEFT(A2,FIND("]",A2&"]")-1),1,FIND("[",A2&"["),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",2),"]","#",2))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",2),"[","#",2)),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",3),"]","#",3))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",3),"[","#",3)),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",4),"]","#",4))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",4),"[","#",4)),"")), " ", ", ")
Let's say this is the text in A2
I have a text [123] and some more [4523] and also [552222] how to extract [22]?
This will create a output of 123,4523,552222,22 in B2
There is no "extraction" in your question, just removal. The formula below replaces the unwanted characters with "", thereby removing them. Please try it.
=SUBSTITUTE(SUBSTITUTE(A2,"[",""),"]","")
I have a comma separated value in A2 and same numbers in different cells B1, C1, D1.... I want to match them from comma separated value and find out the count in B2, C2, D2. Please see the image attached you will get the context.
Can we achieve this by formula or macro in excel?
Tried formula:
=LEN(TRIM($A$2))-LEN(SUBSTITUTE(TRIM($A$2),C1,","""))
Also, I have two data sets where I will be using this formula to find out the count of number from comma-separated value and based on count I want the repeated ones to come in a different cell please refer the image for better understanding.
Probably not the best solution but get the job done. Please note it is case-sensitive and please make sure to press Ctrl+Shift+Enter upon finishing this formula.
{=SUM(--(EXACT("!"&TRIM(MID(SUBSTITUTE($A2,",",REPT(" ",100)),(ROW(INDIRECT("1:"&LEN($A2)))-1)*100+1,100)),"!"&B1)))}
You can replace ! in the above formula with a unique symbol that will never appear in the text string to be safer.
The logic is to SUBSTITUTE the comma , with and long string of blanks, then use MID to find each value in the text string and return the result as an array, then use EXACT to match each value in the array with the look up value and return a new array of TRUE and FALSE, then SUM up all TRUE which will give the count of the look up value.
UPDATE #2
As requested by OP, here is one way of solving the second query which is to match the same value with the same occurrence from two text strings separated by comma ,.
The formula in Cell C2 is from the original solution which is used to find the occurrence of a given value in a text string;
The formula for Range C6:K6 is an array formula as shown below. I used a helper row to layout the matching values, and excluding the one that has 0 count for both data set;
{=IFERROR(INDEX($C$1:$K$1,,AGGREGATE(15,7,COLUMN(INDIRECT("1:"&COLUMNS($C$1:$K$1)))/($C$2:$K$2=$C$3:$K$3)/($C$2:$K$2>0),COLUMN()-2))&",","")}
The formula in Cell L8 is concatenating all values from Range C6:K6 and remove the last comma , from the final text string:
=LEFT(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6),LEN(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6))-1)
The following worked for me, give it a try:
Formula in B2:
=(LEN(","&SUBSTITUTE($A$2,",",",,")&",")-LEN(SUBSTITUTE(","&SUBSTITUTE($A$2,",",",,")&",",","&B$1&",","")))/LEN(","&B$1&",")
Drag right...
A simpler way of doing it is to simply calculate the difference in the length of the string minus the length of the string when replacing the value searched by nothing and dividing by the length of the string searched
The formula would be:
=(LEN($A$1)+1-LEN(SUBSTITUTE($A$1&",",B1&",","")))/LEN(B1&",")
There is a much simpler solution:
=COUNTIF(SPLIT($A$2, ","), B1)
I have a list in excel that contain location but some cell have multiple locations separated by " _ " character for Example "_ Location1 _ Location 2" When there are only 1 location I can use Sumif to search for string and add the numbers next to the cell as shown here
My problem is not searching for a string but searching for a character in a list and finding how many there are in the cell it find I was going to add the formula in a different cell then the ones shown above
example formula NOT REAL
=sum(Sumif($A$4:$A$250,"* ~ Location1*",$C$4:$C$250)/Search($A$4:$A$250," ~ "))
I know search does work like this but as an example code this is what I imagine
to find the sum of each location use this array formula:
=SUMPRODUCT((ISNUMBER(SEARCH(D4,$A$4:$A$9)))*($C$4:$C$9/(IF(ISNUMBER(FIND("_",$A$4:$A$9)),LEN($A$4:$A$9)-LEN(SUBSTITUTE($A$4:$A$9,"_","")),1))))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter. If done correctly then Excel will put {} around the formula.
Enter the formula in E4, Hit Ctrl-Shift-Enter, then copy/fill down.
Then to get the total for all simply sum the rows above.
To do it with regular formulas:
You will need a helper column with the following formula:
=C4/(IF(ISNUMBER(FIND("_",A4)),LEN(A4)-LEN(SUBSTITUTE(A4,"_","")),1))
I put mine in Column G.
Then we can use a simple SUMIF():
=SUMIF(A:A,"*" & D4 & "*",G:G)