I'm trying to compare the contents of pairs of horizontally adjacent cells in excel.
Column A contains text formatted as a list (abc, def, ghi, jkl) and column B contains one of the elements of the list (abc). How would I search the contents of cells in column A for the exact text of cells in column B?
I don't have enough reputation to include an image in my post but I hope the question is clear enough. Thanks in advance!
[A2] = abc, def, ghi,jkl
[B2] = def
[C2] ="," & SUBSTITUTE(A2," ","") & ","
[D2] =FIND(TRIM(B2),C2)
[E2] =FIND(TRIM(B2),"," & SUBSTITUTE(A2," ","") & ",")
[F2] =IFERROR(FIND(TRIM(B2),"," & SUBSTITUTE(A2," ","") & ","),0)
[Final] =IF(IFERROR(FIND(TRIM(B2),"," & SUBSTITUTE(A2," ","") & ","),0), "Found", "Not found")
In C2 all blanks are removed and a comma added before and after the string. This revised string is tested in D2.
E2 sees the reference to C2 (in D2) replaced with the formula from C2.
F2 embeds the ready formula in an IFERROR function so that it returns 0 if no match is found.
By this method the formula returns either a number, a character position where a match was found) or 0. [Final] embeds the entire formula in an IF statement which converts the result to something you can use.
For testing and studying just copy A2 :F2 from above to a blank worksheet and place the final formula anywhere, perhaps G2. From there it can be copied down as required. C2:F2 are just for explanation and not required for the [Final] to function.
Edit
The above will find the string "abc" in "abcd". To prevent that please modify the search string as follows.
[D2] =FIND("," & TRIM(B2) & ",",C2)
and the final
[Final] =IF(IFERROR(FIND("," & TRIM(B2) & ",","," & SUBSTITUTE(A2," ","") & ","),0), "Found", "Not found")
Related
I am looking for an excel formula that either counts or returns true if the cell contains a word pattern (basically wanted to know if any such cell exists), but formula shall recognize a cell as valid only if
Requirement 1 : complete word pattern to be present and as a single word in the cell being checked(Eg: if ab12 is pattern, ab123 is not valid, only ab12 is valid)
Requirement 2 : the matching word can be either in the beginning or end or in middle of the cell being checked
Requirement 3 : The input cell(s) being checked may contain this matching word and can contain prefix/suffix as " "(space) or a line break/feed . Hence, the formula shall identify this cell as valid for both these scenarios
Example word pattern : ab-1_cd_1234
At the moment I have tried both formulas below (also tried with " ","*","~" in the criteria) but didnt work :
Formula 1 : =ISNUMBER(SEARCH(A2,B2))
Here, A2 is the pattern, B2 is the input to verify and will be verified in full B column
Formula 2 : =COUNTIF($B:$B, "* " &A2& " *")
Here, B:B is the input column and A2 is the pattern
Also, I got to know that there is a wildcard in word < and > that defines a word beginning and end, but the same didnt work in excel.
So, it would be great if I can get any formula that works in excel
You can try following formula:
=SUMPRODUCT(--($A$2=FILTERXML("<a><b>" & SUBSTITUTE(SUBSTITUTE(B2,CHAR(10),"</b><b>")," ","</b><b>") & "</b></a>","//b")))>0
Edit
To solve problem with empty strings:
=SUMPRODUCT(--($A$2 & "#"=FILTERXML("<a><b>" & SUBSTITUTE(SUBSTITUTE(B2,CHAR(10),"#</b><b>")," ","#</b><b>") & "#</b></a>","//b")))>0
Edit 2:
To count number of cells which contains pattern you can use array formula:
=SUMPRODUCT(--(IFERROR(SEARCH(" " & A2 & " "," " & SUBSTITUTE($B$2:$B$10,CHAR(10)," ") & " "),0)>0))
Array formula after editing is confirmed by pressing ctrl + shift + enter
Please try this formula, where A3 is a text to be searched and the text to be found is in A1.
=IF(ISERROR(FIND(" "&$A$1&" "," "&SUBSTITUTE(A3,CHAR(10)," ")&" ")),"",TRUE)
I'm new to stack overflow so I apologize if this is a horrendously stupid question. I am wondering if there is a function or way to code a function in excel that will combine a column of cells with plain text and convert them into one cell with the text on a single line? Specifically I want to convert a column of random numbers into a single line of text and insert SPACE+AND+SPACE between them.
Ex.
15133484
12345188
12345888
to
15133484 AND 12345188 AND 12345888
Currently I am copying and pasting all this information into google and then into Word and using find/replace and it is taking forever everytime. If it is possible to just get Excel to do this for me that would be amazing.
Thanks!
If you have Office 365 Excel use TEXTJOIN():
=TEXTJOIN(" AND ",TRUE,A:A)
otherwise one would have to use:
=A1 & " AND " & A2 & " AND " & A3
Or one can use a helper column, B1 put:
=A1
put this in B2 and copy down:
=IF(A2<>"",B1 & " AND " & A2,B1)
And grab the last cell in column B.
A little late, but still:
Reference here
Step 1:
=concatenate(transpose(rngBeg:rngEnd & " AND "))
Step 2:
highlight the transpose statement and then press F9, which substitutes the actual values for the formula.
Step 3:
Remove the curly braces, { }, from the formula. The cell will display the range of reference cells combined with whatever separator chosen after the ampersand sign.
Not a "live" formula, but still far easier than manually concatenating a range of values.
Press ALT+F11 to open Microsoft Visual Basic for Applications,
Insert-> Module
Paste this:
Function Combine(WorkRng As Range, Optional Sign As String = " AND ") As String
Dim Rng As Range
Dim OutStr As String
For Each Rng In WorkRng
If Rng.Text <> "," Then
OutStr = OutStr & Rng.Text & Sign
End If
Next
Combine = Left(OutStr, Len(OutStr) - 5)
End Function
In any cell type =Combine(Range)
i.e.
=Combine(A1:A500)
use concat function if you can add an additional column in the excel like this:
=CONCAT(D3:E5)
Attached sample image with input, additional column, output and formula
I assume you want to merge the data in the 3 cells into a single cell with a space between the 3 data set.
If that is the case then you can do it simply by using the Concatenate function in excel.
In the above example, you have data in Cells A1, A2 & A3.
Cell C1 has the merged data. As you can see, we have used CONCATENATE Function.
The space has been defined in Double quotes. So if you need a Hyphen (-), you can put that in Double Quotes with space “ - ” and it will display the result with Sanjay - Singh - Question
Hope this helps.
The only way my client can provide me these addresses is with the location is in one row: Location Name, street address, city.....and then the row below it contains the zip code. This repeats for 1600 lines.
I, of course, need all the info on one line. Is there a genius out there than knows how to make short work of putting the zip code on the line above it?
If you have address in columns A, B and C in the first row and zip code in column A in second row, try the below formula,
=INDEX(A:A,ROW()*2-1,1)&" " &INDEX(B:B,ROW()*2-1,1)& " " & INDEX(C:C,ROW()*2-1,1)& " " &INDEX(A:A,ROW()*2,1)
If you are starting from some other row other than row 1, you may have to modify the formula a little bit. Hope this helps.
Use a formula to combine your columns.
Here we have some test data.
In column D, specify a formula such as =A1 & ", " & B1 & " " & C1
If you're no familiar with formulas, just use "=" to denote the start of one, and then use "&" to concatenate your values.
As for as implementing this on a multi-row basis, you can easily do so. Once you drag your formula down, it'll auto increment the column names unless you specifically specified it not to. I won't get into that right now though.
So what I would do is just add an IF statement in your formula to account for those rows which are not intended to be used. Using a formula such as this: =IF(B1="", "", A1 & ", " & B1 & " " & A2), I can get the following results.
is possible to get results from columns A-E into column H without use of VBA?
Do you have any suggestions how to do it? Thank you
It needs to look at the row above, so you need to paste it on row 2 and drag from there. On row 1 you will have a ref error but it will still work. For the future you may want to add an extra empty row at the top and have the formula in H2 and down.
H2:
=IF(COUNT(A2:E2)=0,H1,IF(A2<>"",A2&".",LEFT(H1,FIND("|",SUBSTITUTE(H1,".","|",MATCH(TRUE,INDEX(A2:E2<>"",0),0)-1),1))&INDEX(A2:E2,1,MATCH(TRUE,INDEX(A2:E2<>"",0),0))&"."))
I know it looks like a mess, but I'll try to explain it:
IF(COUNT(A2:E2)=0,H1
This is for the empty rows. if empty use the one above
IF(A2<>"",A2&"."
if A2 has a value start with completely new text
INDEX(A2:E2<>"",0)
returns an array of true/false for if the cells are empty
MATCH(TRUE,INDEX(A2:E2<>"",0),0)
This gives you the columnnumber with the new data
SUBSTITUTE(H1,".","|",MATCH...)
Repleces the n-th dot with a | This is so we can use Find to figure out how much of the text above to keep.
INDEX(A2:E2,1,MATCH(TRUE,INDEX(A2:E2<>"",0),0))
is the new data
You can do this by building up the target in a set of columns that can be hidden.
Following from your example above, if you add columns I, J, K and L, use the following formulae:
Cell I1: =A1 & "."
Cell J1: =IF(B1="","",B1 & ".")
Cell K1: =IF(C1="","",C1 & ".")
Cell L1: =IF(D1="","",D1 & ".")
All other rows:
Column I: =IF(A2="",I1,A2 & ".")
Column J: =IF(B2="",IF(I2=I1,J1,""),B2 & ".")
Column K: =IF(C2="",IF(J2=J1,K1,""),C2 & ".")
Column L: =IF(D2="",IF(K2=K1,L1,""),D2 & ".")
Then set column H to be:
=I1 & J1 & K1 & L1 & M1
This roughly translates as "If there isn't a new number, use the number from the row above, unless the parent number has changed, in which case use a blank."
You can hide columns I, J, K and L, or just use alternative columns further to the right if these are not available.
I have a list of unique ids and values on one sheet in excel as in the image below:
Is there a way to return only the values in the order they appear (left to right) on a separate sheet/location? For example, I would want to return for ID '1002' the values 35,32,44.. not the blanks. I am then going to turn those values into a Sparkline.
I am using excel 2010, if that makes a difference.
Thanks!
Sam
Try this formula:
=SUBSTITUTE(TRIM(B2 & " " & C2 & " " & D2 & " " & E2 & " " & F2)," ",",")
EDIT:
_______________________________________________________________________________
Hope this is not too late to answer your question.
Lets assume your data is in Sheet1 as in the image below:
Now, in Cell B2 of Sheet2 enter the following formula:
=IFERROR(INDEX(Sheet1!$B2:Sheet1!$F2, SMALL(IF(ISBLANK(Sheet1!$B2:Sheet1!$F2), "", COLUMN(Sheet1!$B2:Sheet1!$F2)-MIN(COLUMN(Sheet1!$B2:Sheet1!$F2))+1), COLUMN(A1))),"")
This is an array formula so commit it by pressing Ctrl+Shift+Enter
Drag this formula across till Column F and down till Row 4 or as required. This will give you following result.
I guess this is what you are looking for.
Based on "Concatenating Names with Delimiters" by Allen Wyatt you can use the formula below to achieve the result you wanted.
=MID(IF(B2<>"",","&B2,"")&IF(C2<>"",","& C2,"")&IF(D2<>"",","&D2,"")&IF(E2<>"",","&E2,"")&IF(F2<>"",","&F2,""),2,2000)
Regards,