Remove values in a cell found in another cell - excel

I am wondering if there is a formula, or several, that can remove values within a cell (not delete the cell entirely) that are defined in another cell(s).
Example:
"123 New York St Chicago IL 98765" to be "New York St Chicago IL" by using a formula that looks at the cell with the street # "123" and zip "98765" values and remove it from the cell with the full address.
Using Text to Columns is not an option at this point because there are no commas separating values, and all addresses are not in similar formats.
Any help appreciated.

I believe you're looking for Substitute(). This would need to be a helper cell, as formulas in the worksheet cannot remove/delete data.
Example:
A B
1 cat =Substitute(A$4,A1,"") 'output: The chased the dog.
2 dog =Substitute(A$4,A2,"") 'output: The cat chased the .
3
4 The cat chased the dog.
If you are looking to actually remove/delete data, you would need VBA, which isn't appropriate for Google-sheets.

in Google Sheets you can do:
=ARRAYFORMULA(TRIM(REGEXREPLACE(A1:A; "\d+"; )))

Or using Textjoin+Filterxml function, of which Textjoin available in Office365
In B1, formula copied down :
=TEXTJOIN(" ",1,INDEX(FILTERXML("<a><b>"&SUBSTITUTE(A1," ","</b><b>")&"</b></a>","//b[.!=0+.]"),0))

Related

Removing free form text from one cell to another

I have 2 cells in excel and I want to remove free form text from another cell if it exists in another. For example:
Column C2 says "Great Escapes 1122 Apple St"
Column D2 says "Great Escapes"
I want a new cell to result in "1122 Apple St"
I think you can just use Substitute():
=Substitute(C2,D2,"",1)
Try what I have below. just change the formula to fit your cells.

how to find and append values in excel based on how cell begins?

I have > 10000 address records in Excel with a range of input patterns but what I want to deal with is this:
|4 example street | (house number, street name but no city)
Is it possible to write a query to fulfil:
if cell begins with a number then append cell with name of city
Can this be done easily in Excel? R? SQL?
Ok, In which case give this a try..
This is assuming that your address data is in cell A1, and you city is in B1. Also I'm assuming you're using excel 2010 or later - I don't think NUMBERVALUE was available pre-2010.
=IFERROR(IF(AND(NUMBERVALUE(LEFT(A1,FIND(" ",A1)))>1,NUMBERVALUE(LEFT(A1,FIND(" ",A1)))<100),CONCATENATE(A1,", ",B1),A1),A1)
The IFERROR will simply display the data in cell A1 if the formula causes an error.
The AND checks the number is between 1 & 100 (change these values as appropriate
The NUMBERVALUE converts the text returned from the LEFT into a number
The LEFT(A1,FIND(" ",A1)) returns all the text in A1 located before the space. Again, this could be changed to a double space, comma, combination of both etc. Just make sure they are in speech marks.
The CONCATENATE puts the data from A1, followd by a comma and space, then adds the city from B1.
So if A1 = '22 John Street', and B1 = 'Bristol', the result would be '22 John Street, Bristol'
and if A1 = '18GreatRoad' (with no space) the result would remain the same as '18GreatRoad'.
How is the address data formatted? Is there a consistent approach to commas/spaces between street name and address? I'm thinking you use =IF(left(A1,2)>0"&<"999,Right(A1,Find(",",A1)-1),FALSE)
Or something to that effect. You could smarten it up to trim spaces or remove junk text by using trim or changing the -1 at the end of the find.

MS Excel: Search, Find and Extract Specific Text Cell containing text string

Although, I've seen relatively similar or close postings
Using MS Excel MS Excel 2010, I would like to be able to search Cell Range (Column A1:A25), to find if specific text within Cell String (Column C2) is a match in Cell Range (A1:A26) and then Output the corresponding matching Keyword results found in same or adjacent cell. If matching text is not found then display "No Match Found"
Although the sample formula shown below that I'm using does work, but only indicates it found or did not find word within Cell Range I need for it to return the actual matching Keyword text found versus "FOUND" OR "NOT FOUND".
=IF(SUM(IFERROR(FIND(A1:A26,C2),0))>0, "FOUND", "NOT FOUND")
Example:
Cell String contains the following text in Cell C2:
"I found a lost German Sheppard in my backyard on yesterday"
Keyword Search Words: Column A1:A26
TYPES OF DOGS
Affenpinscher
Afghan Hound
Airedale Terrier
Akita
Alaskan Malamute
American Foxhound
American Staffordshire Terrier
American Water Spaniel
Anatolian Shepherd
French Bulldog
German Pinscher
German Shepherd
German Shorthaired Pointer
German Wirehaired Pointer
Giant Schnauzer
Glen of Imaal Terrier
Golden Retriever
Gordon Setter
Great Dane
Greater Swiss Mountain
Great Pyrenees
Greyhound
Harrier
Irish Setter
Irish Terrier
The Returned and displayed results/answer = German Sheppard
Please let me know if this possible, as I would greatly appreciate any assistance to resolving my question.
Miaka3
Assuming you are searching column A for a string(s) in column C type this array formula in B:
=IFERROR(INDEX($C$2:$C$6,MAX(IF(ISERROR(FIND($C$2:$C$6,A2)),-1,1)*(ROW($C$2:$C$6)-ROW($C$2)+1))), "None")
You can see here that I have a search list of multiple characters/strings in C2 through C6. If one of the search strings is found, it will be listed in column B, otherwise it will display "None".
The key to this working is copy the above formula into cel B2 and while you are still in edit mode pressing Ctrl+Shift+Enter instead of just Enter like usual. You will know it works correctly if you see the addition of { and } in the formula once you hit the three key combination. After that you can copy the formula down through A25 or wherever you need.
Note you can make your Search List longer or shorter as needed, just make sure to update your formula to reflect the range. You will want to fill in all of you dog breeds in Column C and change every $C$2:$C$6 in the formula to equal your search list range. And, remember, any change to the array formula requires Ctrl+Shift+Enter to work properly.
This isn't what Excel was designed for, but you can accomplish it with a helper column. Insert a new column at B (this will move C2 to D2). Then paste this formula into B2:
=IF(ISERROR(FIND(A2,D$2)),"",A2)
Fill down that formula until A27 (you said A26, but your example went to A27 if you include the header "TYPE OF DOGS"). This will output the breed of the dog only if it is contained within the text in D2.
Finally, go to whatever cell you would like to contain your output, and paste in:
=CONCATENATE(B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12,B13,B14,B15,B16,B17,B18,B19,B20,B21,B22,B23,B24,B25,B26,B27)

Remove duplicates within Excel cell

Say I have the following text string in one single Excel cell:
John John John Mary Mary
I want to create a formula (so no menu functions or VBA, please) that would give me, on another cell
John Mary
How can I do this?
What I've tried so far was search the internet and SO about the issue and all I could find were solutions involving Excel's built-in duplicate removal or something involving countif and the replacement of duplicates for "". I've also taken a look at the list of Excel functions, especially those from the "Text" category, but couldn't find anything interesting, that could be done on one cell.
The answer is here: https://www.extendoffice.com/documents/excel/2133-excel-remove-duplicate-characters-in-string.html
Function RemoveDupes2(txt As String, Optional delim As String = " ") As String
Dim x
'Updateby20140924
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For Each x In Split(txt, delim)
If Trim(x) <> "" And Not .exists(Trim(x)) Then .Add Trim(x), Nothing
Next
If .Count > 0 Then RemoveDupes2 = Join(.keys, delim)
End With
End Function
Put the code above in a module
Use =RemoveDupes2(A2,",")
A2 contains repeated text separated by ,
You may change the delimiter
Assuming you'll never have more than two distinct names in a cell, this should work:
=MID(A1&" ",1,FIND(" ",A1&" "))&
MID(SUBSTITUTE(A1&" ",MID(A1&" ",1,FIND(" ",A1&" ")),"")&" ",1,
FIND(" ",SUBSTITUTE(A1&" ",MID(A1&" ",1,FIND(" ",A1&" "))&" ","")))
It will show John Mary for all of these:
John John John Mary Mary
John Mary
John Mary John Mary
John Mary Mary
John John Mary
It will show John for all of these:
John
John John
John John John
And it will show nothing if A1 is blank.
As I wrote, it is trivial to solve with VBA. If you cannot use VBA, one method is to use helper columns.
Assume: Your string is in A1
Enter the following formulas:
C1: =IFERROR(INDEX(TRIM(MID(SUBSTITUTE($A$1," ",REPT(" ",99)),(ROW(INDIRECT("1:" & LEN($A$1)-LEN(SUBSTITUTE($A$1," ",""))+1))-1)*99+((ROW(INDIRECT("1:" & LEN($A$1)-LEN(SUBSTITUTE($A$1," ",""))+1))=1)),99)),ROWS($1:1),1),"")
D1: =IF(COUNTIF(C1:$C$5,C1)=1,C1,"")
Select C1 and D1 and fill down until you start getting blanks
E1: =D1
E2: =TRIM(CONCATENATE(D2," ",E1))
Select E2 and fill down.
The contents of the last cell filled in column E will be your result.
If you want to have a cell which automatically returns the contents of the last cell in column E range, you can use a formula like:
=LOOKUP(REPT("z",99),$E$1:$E$100)
Without a formula: Text to Columns with space as the delimiter, transpose the output, apply Remove Duplicates to each of the columns individually, then transpose the result.
Found a solution that might work if you are also the one making the list.
when you make the list if you are doing it by combining the cell above with the current line, you can check to see if the value is already in the above cell using the following code:
if(iserror(find(value_to_be_added,previous_concatenation)),
previous_concatenation&" "&value_to_be_added,previous_concatenation)
Did you try the textjoin function? (available in Excel 2016, not sure about previous versions). Was just looking for something similar and this seems to do the job for me on a column where I have multiple values more than once.
=TEXTJOIN(delimiter;ignore_empty;text)
define delimiter in any way you need it
ignore empty can be true or false, depending on what serves your needs
text would be your array of values - using the unique function within here (see example below) will filter out any multiples of any string (I am using it for numbers and it works)
Example:
=TEXTJOIN(" ";TRUE;UNIQUE($A$1:$A$16))
Guess this might be Excel's equivalent to google sheets' join function. Textjoin comes up if you type in =join - I took the formula provided in user11308575's post above but removed the parantheses and its content, then went from there.
Hope this helps (even though the thread is already old) ;)
If one has access to TEXTJOIN one could use:
=TEXTJOIN(" ",,FILTERXML("<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s[not(preceding::*=.)]"))
I found the answer below in this thread https://superuser.com/questions/643909/remove-duplicate-entries-in-one-cell
=join(" ",unique(transpose(split(A1," "))))

Excel - Replace cell value based on a value in another column

I am wondering if there is a way to replace a cell value from another list without having to write a VB script.
Here is the problem I am trying to resolve:
I have last names in a column:
Smith
Jones
Taylor
etc.
I have another column with IDs e.g.
Smith_ID
Taylor_B
Jones_C
I would like to replace Smith with Smith_ID, Jones with Jones_C etc. Obviously my list is much longer than 3 entries.
He can do it.
Extract column IDs with "_" character by "Text to Columns"
A column
Smith
Jones
Taylor
B column
Smith
Taylor
Jones
C column
ID
B
C
Now write to following formula
=CONCATENATE(A1;"_";VLOOKUP(A1;$B$1:$C$3;2;FALSE))
I hope you do
If you have a common value between the 2 lists, then you can use Vlookup() (see link for better examples) to match the 2.
Using your example, you have Sheet1 that says:
Smith
Jones
Taylor
In Sheet2, you have:
Smith 4
Jones 9
Taylor 6
Then do this:
In Sheet1, add a column with the formula =vlookup(A1,Sheet2!$A$3:$B$3,2,False). This will return 4 for the 1st row, 9 for the 2nd, etc.
(Optional) If you want to get rid of the original values completely, you can then copy&paste values and delete the original column OR just hide the original column.
Is this what you're looking for?
To answer this question under general situation, suppose you have two columns as followed:
A Smith,Jones,Taylor,Kevin,Yell,Ashton...
B John Harvard, Yell USC, Kevin Cruise, Ashton Bond, Smith Stone, Taylor Shift...
The classic case here is that you have two pretty much alike columns only with slightly difference. It could be a typo or some other mistakes.
What you want to do is to replace cells'value in column A by them in column B, if we assume that column B is the right thing you want.
So for each cell in A, you want to know the position of its approximate match in column B. For example, given A1(Smith), you want to know where Smith Stone is, in this case, B5.
Begin with a new column C, combined with match function and wildcard, filled C1 by the following formula:
row_index=match(A1&"",$B$1:$B$6,0)
you now extract row_index of every approximate match corresponding to column A. Then by using
=index($B$1:$B$6,row_index,0)
which returns you "Smith Stone" in cell C1. Same for other cells.
*Remark: The biggest flaw for this method is that it kind of requires the approximate match in B for each cell in A should be unique.
I had 2 columns, one was an Vendor Name, the 2nd was the Vendor Address but it also contained the Vendor Name. I needed to strip out the Vendor Name which would leave me with the Vendor Address without the Name.
For example if one column had "Con Ed", the next column had "Con Ed 123 Street, New York, NY 11111", I needed to replace "Con Ed" with null and just have "123 Street, New York, NY 11111" in a column.
Here's what I did and I will also let you know what you can do to accomplish your goal.
First I created a new column and set that to the Length (using the LEN() function) of the Vendor Name.
Then I created another new column and set that to the length of the Vendor Address.
A third column and was set to use the Right() function. Where the text is the Vendor Address and the length is the Length of the Address minus the length of the Vendor Name.
So consider: "Con Ed 123 Street, New York, NY 11111"
1st column: (Length of Vendor): len(Con Ed) = 6
2nd column: (Length of Vendor address): len(Con Ed 123 Street, New York, NY 11111) = 37
3rd Column: Right([Vendor Address], 31 (37-6)) = ", New York, NY 11111"
Lastly I just applied the TRIM function to the 3rd column.
In your case you would just want to use the Concatenate function to append the the original column & the new column.
So in summary you'll have the below columns:
Column 1: Names:
(Smith,Jones,Taylor)
Column2: IDs:
(Smith_ID,Taylor_B,Jones_C)
Column3: Len([Names])
Column4: Len([IDs])
Column5: The "replace" function
= TRIM(Right([IDs], ([Column4] -[Column3] ))
Column6: String put back together
=Concatenate([Column3],[Column5])
=INDEX('All_Linguists_All_ProjectsFri J'!$DA$2:'All_Linguists_All_ProjectsFri J'!$D$71355,MATCH(A2,'All_Linguists_All_ProjectsFri J'!C:C,FALSE),1)
Dont have time to explain it, but if you know how to write formulas in excel, this should be useful. Sorry for not explaining.
Hope you are using excel and in that you want to replace value of one cell of raw from another cell of same raw and this has to be done for entire column and not form selected raw.
In this case you can copy the values which you want to kept (i.e. ID column) and then pest the same in column Last name.
If values are in same raw then there is no problem and from your query it appears that values are in same raw.
I use this formula when searching cell B1 for the letter "s", if found then I concatenate the word "addition" to the value of cell A1 otherwise just take the value of cell A1.
=IF(ISNUMBER(SEARCH("s",B1))=TRUE,CONCAT(A1, " addition"),A1)

Resources