I have a excel sheet where I have columns that say
"I like TSX but I prefer 350"
"I like beamer but I am fan of S-Class"
I want to replace this with
"I like Acura but I prefer BMW"
"I like BMW but I am fan of Mercedes"
I have another excel sheet with the match and replace values. For example
TSX, Acura
TL, Acura
350 BMW
Beamer, BMW
etc.
I know how to use vlookup, but this is way advance for me. Any help? Thanks you.
Rather than use vlookup at all, if you don't have many types of cars you could simply use SUBSTITUTE. Works as
=SUBSTITUTE(A1, "TSX", "ACURA")
Then wrap it many times, once for each possibility:
=SUBSTITUTE(SUBSTITUTE(A1, "TSX", "ACURA"),"S-CLASS", "MERCEDES"))
If you have many possibilities, this will either need 2 helper columns, or vba. Let me know if that's the case. Basically without vba you will need to search for the first term in 1 column, then put the 2nd term in the second formula, then replace the 1st term with a vlookup'd equivilent, then replace the 2nd term with a vlookuo'd equivilent (using substitute as above).
Edit
Reading the q again it seems there are many possibilities, so we will need to use two helper columns and areay formulas to solve. VBA is likely better, but In on my phone so cant error test anything, and you might not want vba anyway.
The principle for these helper columns is going to be to find which 2 vehicles exist in the text. Once you know which two exist, you can simply replace both as above.
The first stage of the formula we will be putting in colns B and C, (assuming your 'vlookup text' is in columns A and B on sheet2 from rows 1 to 100) is:
=If(iserror(search($A1,sheet2!$A$1:$A100)),"",row(sheet2!$A$1:$A$100))
This is an array formula, which works on each cell in the range you give it. To confirm it, press CTRL + SHIFT + ENTER instead of just ENTER. It gives you an array of results, that you need to collapse into a single answer. so in column B, wrap it in a MIN function. For column C, wrap it in a Max function.
So now column B shows the row number of 1 matching term, and row C shows the row number of the 2nd matching term.
So now in column D, we know the row number of the first match, the first replacement term, and thend match and replacement term. Replace everything as follows:
=Substitute(substitute(A1,INDEX(SHEET2!$A$1:$A$100, B1),INDEX(SHEET2!$B$1:$B$100, C1)),INDEX(SHEET2!$A$1:$A$100, C1),INDEX(SHEET2!$B$1:$B$100, B1)))
Make sure you confirm with CTRL SHIFT ENTER instead of just enter.
Apologies if this isnt formatted 100%; Im on my phone and will error check it later if it causes problems. Let me know if you have questions about how this works.
Related
Good evening all,
I want to do a sumifs() but the two columns do not always have the exact same values. However, the first 8 characters would always match in both columns. For example the value I wish to look up is "00123456 - Nice Salad". The data I wish to search in sits in Column A with value to return in Column B.
I know I can use the left() function on the value to lookup but I am unsure how best to search against just the first 8 characters in column A. I would like the formula to return the number 6 from column B in this example.
Current formula is as follows: =sumifs(left(00123456 - Nice Salad,8),A:A,B:B)
I hope this all makes sense and any help is appreciated.
Many thanks, Alan.
Screenshot/this sheet refer:
One way is with a regular sum equation:
=SUM(1*(LEFT(A2:A4,8)=E2)*(B2:B4))
However, this can be computationally intensive (i.e. if you have plenty of data/rows to evaluate). The better, in my view, is simply a sumifs with wildcard '*', i.e.:
=SUMIFS(B2:B4,A2:A4,E2&"*")
How can i create a vlookup or VBA code such that the Vlookup function doesnt always take the first but after the first has been taken also a second value etc.
I think it becomes clearer with a screenshot
Some further explanation:
Column A is an identifier (in the real sample the cusip (an Identification number) of a company)
Column B represents a Dealnumber.
But not for every deal cusips are availble (explains empty spaces), and a company can occur in several deals(-> values in column A are not mutually exclusive)
Since the values in column A are not mutually exclusive, i have to "map" the values of column B, which are mutually exclusive, to the occurance in column D
Use this, but it requires a title row on the data column:
=IF(D1=D2,E1,INDEX(B:B,AGGREGATE(15,7,ROW($B$1:$B$6)/($A$1:$A$6=D2),COUNTIFS($D$1:D1,D2,$D$2:D2,"<>"&D2)+1)))
It does not matter what the value in D1 is but the formula must be placed in the second row as it uses the first row as a check for changes.
Since this is an array type formula the references should limit themselves to the data set and not use full column references, But we can use INDEx(MATCH()) to do that automatically:
=IF(D1=D2,E1,INDEX(B:B,AGGREGATE(15,7,ROW($B$1:INDEX(B:B,MATCH("zzz",A:A)))/($A$1:INDEX(A:A,MATCH("zzz",A:A))=D2),COUNTIFS($D$1:D1,D2,$D$2:D2,"<>"&D2)+1)))
If I am understanding how your Columns A & B are being populated (by looking at occurrences in C & D), why not just use the C&D data?
You could find the number of tasks such that (I have this in D2):
=IFERROR(IF(C2=C1,D1,D1+1),1)
This will give the occurrences without using the Vlookup or Index/Match, adding 1 where the task changes (the iferror is used to give the first "1", since you can't add "occurrence" + 1).
You probably have your answer by now. Here's a nice (additional) solution.
=IFERROR(INDEX($B$3:$B$13, SMALL(IF(D$2=$A$3:$A$13, ROW($B$3:$B$13)-2,""), ROW()-2)),"")
or
=IFERROR(INDEX($B$3:$B$13,SMALL(IF(D$2=$A$3:$A$13,ROW($A$3:$A$13)- MIN(ROW($A$3:$A$13))+1,""), ROW()-2)),"")
See this link:
https://www.ablebits.com/office-addins-blog/2017/02/22/vlookup-multiple-values-excel/
To get VBA code, enter the function and get it working, then turn on the Macro Recorder, click on the primary cell (first cell), hit F2, hit Enter to commit the change, and double click the black cross to fill down. Now, you should have all your VBA, and of course you can modify your code to do whatever you want.
I'd like to use column D as Index or lookup value. Then I want to concatenate the values from column B and C into Column E.
I can use =VLOOKUP(D2,A2:C6,2,FALSE) or =INDEX($B$2:$B$6,MATCH("Person 1",$A$2:$A$6,0)) but I don't know how to use it multiple times in the same column.Is there a way I combine those to search multiple times in the same column?
I'd be open to using vba if that would be a better option, just still not sure about the multiple times per column.
I couldn't figure out magic one in done formula. Richard Tompsett is probably correct with VBA solution. I'd recommend the following series of steps if VBA is out of the question.
(1) Sort by column A. This will group Thing 1 and Thing 2 together into discrete ranges per person.
(2) In cell F2, type =Transpose(B2:C3) and hit F9. Should convert to look like ={"A","D";1,4}, then delete curly brackets and equal sign. This is the range for Person 1 (manually).
(3) In cell E2, enter =SUBSTITUTE(SUBSTITUTE(F2,"""",""),";",","). Should now appear as ' A,D,1,4 '
Repeat for each Person
I have a long column in an Excel spreadsheet that I'd like to match with another long column in the same sheet.
The columns look like:
And I want to make a script that will allow me to check A to F using B to copy and paste F,G,H to B,C,D if A and F match to look like:
The problem is that A and F don't usually match exactly; only most of the words - as you can see with "metal corp & company" vs "metal corp".
Is there any way I can do this via script? I know I can see if they match exactly using something like =NOT(ISERROR(MATCH(A2,$F$2:$F$5, 0))) etc....Or to explicitly state the name in quotations, but nothing to match only part of the entry to another.
Also, is there any way to automatically paste F,G,H if the match is found?
Ok, you can do a vlookup and break the formula with copy/paste values if needed. you may not need to do that.
So, you need to consider how to make vlookup work. vlookup can take a value and search for it in an array and return a corresponding value in that row of the array that it is found. given your ask for the following values along the right, this should work well if we can get a value to be matched. afterwards just repeat the same formula with +1 to each column being returned (F, G, H).
So, your issue is getting the match to work since you think most of the time the values do not match 100%, but are close. you need to make them match, somehow. either by manually assigning an lookup table where the alias's are aligned. e.g. on another sheet, in column A, have "metal corp & company" and in column b, have "metal corp" or by a formula to establish a match. depending on the number of rows, doing it manually may be substantially less work than a formula. a formula can work it the alias's are consistently wrong in a certain fashion. if it is random, then a formula won't work.
I would try something as simple =vlookup(value,array,column,TRUE). the true value will return an approximate match instead of exact match.
See example screenshot, the only formula is in column B. "hi" is close enough to "high" and then "there" is returned from column e.
I have tied quite a few combinations of the AND/OR functions and have had no luck.
Here is what I need to create:
In column B, I have Firm ID's, which range from two numeric characters to six numeric characters.
I need every the letter "I" and a certain number of zeros before each Firm ID in column B.
-So if the Firm ID has two numbers, I need to add "I0000" to the left of the Firms ID in column B. So the end result would be "I0000##", totalling seven characters.
-If the Firm ID has three numbers, I need to add "I000" to the left of the Firms ID in column B, So the end result would be "I000###", totalling seven characters.
-and so on and so fourth for 4,5, and 6 character firm ID's (The Largest firm ID I have is 6 characters, so it would only need the letter "I" added)
I was trying to use something along these lines =if(len(b2=6),concatenate("I",B2),IF(len(b2=5),concatenate("I0",B2),If(Len---------you get the idea. It wasn't pretty, and it only added an "I" to all my Firm ID's.
I realize that it will require the use of either an OR( or AND( function. I tried to write it to no avail. I am a visual learner, and don't mean to troll anyone reading this, but if its not to much trouble it would really help me to see the actual function written out, so I can compare it to my incorrect function and see my mistakes.
Just pointing me to an excel training site about AND/OR functions will not help me.
For a formula solution, you could use the TEXT function:
=TEXT(B2,"I000000")
Alternately, you could select column B, right-click -> format cells -> Custom -> type I000000 -> OK
Doing a custom format for cells in column B should do the trick, with no coding / functions needed. Choose the cells you want to change, right click, go to format cells. From there choose the Number tab, and choose the Custom category. You could do something like "I"000000 in the box under "Type".