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

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)

Related

Appending separators in the formula

Can someone help on this? I have column A with telephone number and Column B with country code. I want to remove the country code in column A if it is there to avoid duplication. Can someone help me?
Column A 1234567 Column B 1 Column C 1234567
Column C should have the formula to check if 1 is already in the beginning of the cell value A, if yes, it'll remove it, but if not, column B value will be added to it. Another scenario is below: Column A 234567 Column B 1 Column C 1234567
Also, I would like to add separators in this formula after the country code, and after three digits of the country code based on column 1 with removed country code in it.
How to append it in this formula?
=IF(B1 = --LEFT(A1, LEN(B1)),A1,--(B1&A1))
Appreciate your answer!
As far as I understand what you describe, you may be after something like this:
="+"&TEXT(B1,"0")&"-"&
IF(LEFT(TEXT(A1,"0"),LEN(TEXT(B1,"0")))=TEXT(B1,"0"),
MID(TEXT(A1,"0"),LEN(TEXT(B1,"0"))+1,99),
A1)
The statement about "after three digits of the country code based on column 1 " is unclear. This formula gives you tools to add characters before and after the country code, while it removes country code duplication.
edit after comments You don't really describe it, at least not clearly, but it looks like you want a vertical bar after the country code and again after the first three digits of the phone number. The formula to achieve that is
=TEXT(B1,"0")&"|"&
REPLACE(IF(LEFT(TEXT(A1,"0"),LEN(TEXT(B1,"0")))=TEXT(B1,"0"),
MID(TEXT(A1,"0"),LEN(TEXT(B1,"0"))+1,99),
A1),4,1,"|")
another edit after stitching together what else you might want but don't clearly describe: If column B can possibly contain either numbers like 1 or 63 but also text that starts with a country code, followed by a space and some other stuff, like 63 2, then you can use this formula
=LEFT(TEXT(B2,"0"),FIND(" ",TEXT(B2,"0")&" ")-1)&"|"&
REPLACE(IF(LEFT(TEXT(A2,"0"),LEN(TEXT(B2,"0")))=TEXT(B2,"0"),
MID(TEXT(A2,"0"),LEN(TEXT(B2,"0"))+1,99),
A2),4,1,"|")

Partial match when using vlookup formula

I'm trying to fill an empty column of a sheet with data from another sheet. For this I'm depending on VLOOKUP
Here is my formula
=VLOOKUP(RC[-6],Sheet2!C[-3]:C[-2],2,FALSE)
I'm looking for a name in a sheet and takes value from that row. But the issue I'm facing is sometime the value in sheet2 (Where I have to do vlookup) which is actually a person's name doesnt have middle name. It only have first and last name. Since the lookup value as middle name, in that situation the lookup doesn't yields any result. So the plan is to do lookup with the first and lastname only even there is middle name in the lookup value. How can we accomplish that
For example our lookup value (RC[-6]) could be Donald John Trump. But in search sheet (Sheet2) the name could be only Donald Trump. So in result I need Donald Trump row, but it's not since we have Donald John Trump as lookup value.
You can use wildcards in VLOOKUP like the asterisk * for any amount of characters or the ? for one character.
So if your search term is Donald Trump but you want to find also Donald John Trump then you need to add an asterisk Donald *Trump:
=IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=1,LEFT(A1,FIND(" ",A1)-1) & " *" & RIGHT(A1,LEN(A1)-FIND(" ",A1)),A1)
Or if your search term is Donald John Trump but you want to find also Donald Trump then you need to substitute the middle name with an asterisk Donald *Trump:
=IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=2,LEFT(A1,FIND(" ",A1)-1) & " *" & RIGHT(A1,LEN(A1)-FIND(" ",A1,FIND(" ",A1)+1)),A1)
You can then use the above formula as first argument in your VLOOKUP, or use a helper column so you can see what the actual search term is.

Excel - Pick out a string from a range of strings

I have 2 columns of data and I need to use one to pull out one element of the other.
I have a list of addresses, where the entire address is in one cell. There is no standard format or delimiter. I need to pull out the city only into a separate cell.
I also have a list of cities that can be used as a lookup.
What I need the formula to do is look in the address cell and pull out the city, where the city is within my list in point 2.
As an example here is the first 4 rows of addresses;
42493 CLONSILLA ROAD DUBLIN 15 DUBLIN
2 Glenavey Rd Company Antrim Antrim Ireland
Tesco Wexford Road Arklow n a Wicklow Ireland
GROVE SERVICE STATION BAYLOUGH ATHLONE WESTMEATH
And an extract of the towns list;
Duagh
Dualla
Dublin
Duhallow
Duleek
For row 1, the formula needs to look through the towns and bring back Dublin.
Any ideas on this one? I'm a bit lost!
I think you'll need to use an Array Formula
=IFERROR(INDEX($D$1:$D$5,MAX(IF(ISERROR(FIND(LOWER($D$1:$D$5),LOWER(A2))),-1,1)*ROW($D$1:$D$5))-ROW($D$1)+1),"")
would work in the following example, you willl need to use Ctrl + Shift + Enter to confirm the formula as opposed to just Enter
The formula is a bit involved, I've tried to break it down below:
$D1:$D$5 - represents the cities you want to find
LOWER is used to ignore uppercase v lowercase
The FIND formula searches the text in column A for any of D1:D5,
which errors for those not found
ISERROR returns TRUE if a city isn't found and FALSE otherwise
IF converts the TRUEs (not founds) to -1 and the FALSE (found) to 1
This is then multiplied by the ROW number, and MAX selects the
maximum number, which will be the row number of the found city
INDEX then returns the name of the city based on the row number it
receives
In the case where no match is found IFERROR returns a blank

Find a Match between Two Columns by Referring to a List and put the result in a new column

I have two columns (column P and column Q) which has a list of companies.
Within that list of companies in column P and Q, there were companies which are called 'global companies'.
I also have a list of that 'global companies' which I got it via email (not in excel format). In that email, there are about 85 companies listed.
The company name in the 'global companies' list and also in column P and column Q were not consistent. For example, there are company written as "Jane and Frank" and the same company written as "Jane & Frank". Another example is "H Tech Japan" and there is also "H Tech UK", but it is the same company.
How to make excel can identify between column P and column Q which one is a 'global company' (by referring to where I put the 'global companies' list; perhaps in a column of the same sheet or somewhere else) and put the result of that 'global company' in column R (a new column beside column Q)?
There is a way, but not an easy one....
1) First of all, copy and paste all contents of columns P and Q in a new sheet, one under another, so it becomes a single column with company names.
2) On the ribbon Data, select Remove Duplicates, then OK.
3) Sort the column in alphabetical order. From here, you have two options:
3a) If your list has a manageable size, you can manually do the task. The idea is to copy this column, say A, onto column B, and manually fix the names so they match a pattern (in this case, your 85-item list). You will have something like:
A B
H Tech Japan H Tech Japan
H Tech JapĆ³n H Tech Japan
H Tech UK H Tech Japan
H Tech jp H Tech Japan
Jane & Frank Jane & Frank
Jane et Frank Jane & Frank
Jane and Frank Jane & Frank
Jane y frank Jane & Frank
Jane & FRaNK Jane & Frank
3B) Now, if the list size is unmanageable to do something by hand, you can automate the process to a reasonable extent (I'd say 70% or more of the matches are accurate) using an Excel add-in called Fuzzy Lookup; you can download it on Microsoft:
http://www.microsoft.com/en-us/download/details.aspx?id=15011
It does pretty much the same thing: using a fuzzy algorith, it matches patterns of similar text sequences, and return a column of matches. There are lots of YouTube videos explaining how to use the Fuzzy Lookup for Excel, and the time you "waste" learning it is totally worth.
Note that, even using this program, It's always a best practice to check the matches and manually correct not found items or mismatches, even if there are few of them.
4) By one way or another, you should now have a column with inputs from the original columns P and Q (column A from the new Sheet), and the correct counterparts next to it (column B). Now, back to the original table:
Open a new column next to P
Use a Vlookup to search the values on P on the corrected list [=VLOOKUP(P2;[the list range];2;0)]
Double-click the small black mark on the inferior right part of cell Q2, to expand the formula until the last item of the column.
The formula range should be selected now. If not, select it (say, Q2 to Q[last row]), copy with CTRL + C, paste as a value with ALT + C V V. Select the range again, CUT it and PASTE in cell P2 (replacing the old values).
Do the same process for column Q.
5) Having the 85-items list in another sheet, create two new columns (say, IsGlobal_P and IsGlobal_Q) and paste the following formula to return "Yes" if it's global, and "No" if it's not:
=IF(ISERROR(MATCH(P2;Sheet2!$A$1:$B$300;0));"No";"Yes") (for variable IsGlobal_P)
=IF(ISERROR(MATCH(Q2;Sheet2!$A$1:$B$300;0));"No";"Yes") (for variable IsGlobal_Q)
Now you have the Global companies identified!
Hope it helps...

Find something in column A then show the value of B for that row in Excel 2010

Basically my problem is that I have a string in one cell in excel, I then need to see if that string exists in another row (not one cell but the whole row) and if so then print the contents of another cell in the same row but in another column.
I will give a basic example:
Title Answer
Police 15
Ambulance 20
Fire 89
Now I need to scan the title column for, say, "Police" and then populate the cell with the value under Answer (in this case 15).
I cant just say IF(A2="Police";B2;"" as I need the scan the whole of the Title column.
I have tried using IF(COUNTIF(A$2:A$100;"Police"); which scans the contents of A2 to A100 for the string Police, and know how to make it print a constant (just put something after the ;) but cant work out how to make that "constant" a variable that changes depending on the found row. So if the COUNTIF found Police in cell A44 then the answer to my formula would be B44, the same as if it found Police in A62 then my formula should show B62
I hope this makes sense and that someone can help me :)
Note that I am using excel 2010 and need a normal formula as I can not use scripting for this document.
EDIT:
Here is what I have so far, note that the spreadsheet I am using is far more complex than the "simple" example I have in the question...
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
This is showing "RuhrP" in every answer where "RuhrP" is found in F9 and not the answer I want which should be that found in RuhrPumpen!I$5:I$100 where the cell index is the same as that for the A coloum where A9 was found. Again, sorry for the complexity I cant think of any better way to word it.
I note you suggested this formula
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
.....but LOOKUP isn't appropriate here because I assume you want an exact match (LOOKUP won't guarantee that and also data in lookup range has to be sorted), so VLOOKUP or INDEX/MATCH would be better....and you can also use IFERROR to avoid the IF function, i.e
=IFERROR(VLOOKUP(A9;Ruhrpumpen!A$5:Z$100;9;0);"")
Note: VLOOKUP always looks up the lookup value (A9) in the first column of the "table array" and returns a value from the nth column of the "table array" where n is defined by col_index_num, in this case 9
INDEX/MATCH is sometimes more flexible because you can explicitly define the lookup column and the return column (and return column can be to the left of the lookup column which can't be the case in VLOOKUP), so that would look like this:
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH(A9;Ruhrpumpen!A$5:A$100;0));"")
INDEX/MATCH also allows you to more easily return multiple values from different columns, e.g. by using $ signs in front of A9 and the lookup range Ruhrpumpen!A$5:A$100, i.e.
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH($A9;Ruhrpumpen!$A$5:$A$100;0));"")
this version can be dragged across to get successive values from column I, column J, column K etc.....
Assuming
source data range is A1:B100.
query cell is D1 (here you will input Police or Fire).
result cell is E1
Formula in E1 = VLOOKUP(D1, A1:B100, 2, FALSE)
I figured out such data design:
Main sheet:
Column A: Pump codes (numbers)
Column B: formula showing a corresponding row in sheet 'Ruhrpumpen'
=ROW(Pump_codes)+MATCH(A2;Ruhrpumpen!$I$5:$I$100;0)
Formulae have ";" instead of ",", it should be also German notation. If not, pleace replace.
Column C: formula showing data in 'Ruhrpumpen' column A from a row found by formula in col B
=INDIRECT("Ruhrpumpen!A"&$B2)
Column D: formula showing data in 'Ruhrpumpen' column B from a row found by formula in col B:
=INDIRECT("Ruhrpumpen!B"&$B2)
Sheet 'Ruhrpumpen':
Column A: some data about a certain pump
Column B: some more data
Column I: pump codes. Beginning of the list includes defined name 'Pump_codes' used by the formula in column B of the main sheet.
Spreadsheet example: http://www.bumpclub.ee/~jyri_r/Excel/Data_from_other_sheet_by_code_row.xls
Guys Its very interesting to know that many of us face the problem of replication of lookup value while using the Vlookup/Index with Match or Hlookup.... If we have duplicate value in a cell we all know, Vlookup will pick up against the first item would be matching in loopkup array....So here is solution for you all...
e.g.
in Column A we have field called company....
Column A Column B Column C
Company_Name Value
Monster 25000
Naukri 30000
WNS 80000
American Express 40000
Bank of America 50000
Alcatel Lucent 35000
Google 75000
Microsoft 60000
Monster 35000
Bank of America 15000
Now if you lookup the above dataset, you would see the duplicity is in Company Name at Row No# 10 & 11. So if you put the vlookup, the data will be picking up which comes first..But if you use the below formula, you can make your lookup value Unique and can pick any data easily without having any dispute or facing any problem
Put the formula in C2.........A2&"_"&COUNTIF(A2:$A$2,A2)..........Result will be Monster_1 for first line item and for row no 10 & 11.....Monster_2, Bank of America_2 respectively....Here you go now you have the unique value so now you can pick any data easily now..
Cheers!!!
Anil Dhawan

Resources