Compare and match the columns in Excel - excel

Column "A" is static and can't be change. I have to re-arrange column B to match it with column A.
Column "C" is a part of column B and should be re-arranged accordingly. See the end result.
A B C
SGK LSP BAL BHARATI PUBLIC SCHOOL
RNG KQN BAL BHAVAN INTERNATIONAL SCHOOL
LSP SGK BASAVA INTERNATIONAL SCHOOL
KQN LAK BGS INTERNATIONAL SCHOOL
QEH HDY BRAIN INTERNATIONAL SCHOOL
QEH BRAIN INTERNATIONAL SCHOOL
RNG BRAIN INTERNATIONAL SCHOOL
I want the end result to be in this format:
A B C
SGK SGK BASAVA INTERNATIONAL SCHOOL
RNG RNG BRAIN INTERNATIONAL SCHOOL
LSP LSP BAL BHARATI PUBLIC SCHOOL
KQN KQN BAL BHAVAN INTERNATIONAL SCHOOL
QEH QEH BRAIN INTERNATIONAL SCHOOL
HDY BRAIN INTERNATIONAL SCHOOL
LAK BGS INTERNATIONAL SCHOOL
What would be the formula for this? I have a thousand such files.

If I understand you properly, to solve this problem you will need to use the VLookup function.
Create a new spreadsheet
Copy the headers over
Copy all of column A
The formula for cell B2 would be =A2
The formula for cell C2 would be =VLOOKUP(B2, Sheet1!$B:$C, 2, false)

Create a custom list from your A column, then sort B:C according to that.
To create a custom list go to Excel > Options > Advanced > General > Edit Custom Lists... > select as much of Column A as required, Import, OK, OK.
This is a application level setting, so available 'until further notice'.

Assuming your data is as in the image below and you want result in Column H and Column I.
Enter the following formula in cell H2:
=IFERROR(VLOOKUP($A2,$B$2:$C$20,1,FALSE),IFERROR(INDEX($B$2:$B$20,MATCH(0,IFERROR(MATCH($B$2:$B$20,$A$2:$A$20,0),COUNTIF($H$1:$H1,$B$2:$B$20)),0)),""))
This is an array formula so commit it by pressing Ctrl+Shift+Enter.
Then in cell I2, enterthe following formula:
=IFERROR(VLOOKUP($A2,$B$2:$C$20,2,FALSE),IFERROR(INDEX($C$2:$C$20,MATCH(0,IFERROR(MATCH($B$2:$B$20,$A$2:$A$20,0),COUNTIF($H$1:$H1,$B$2:$B$20)),0)),""))
Again, this is an array formula so commit it by pressing Ctrl+Shift+Enter.
NOTE:- Result will not display names that are in Column A but not in Column B.
Second part of the formula is taken from here.

Related

Excel: Find the Position/Location of Each Occurrence of a Specific Word in a String in a Column

Using an MS Excel formula, I would like to find the Position(s)/Location of specific words found within a String of text located in a Range/Column of cells.
I'm using a formula that only identifies and finds the position(s) of a keyword by a single cell versus a column. I'm not able to repeat this action by looking throughout the column cells, using my numeric helper column (Cell D2:D12 "Occurrence") which provides the occurrence of the next position to be found.
Helper columns are welcomed if necessary to achieve the desired results.
The cells highlighted in "Red" is what I'm looking for as the final output results.
See below for formulas used for Column C and D. Text string is located in Column A2:A12.
COLUMN A
DATA TEXT
Dolly would not count her eggs but Count her apples
Tony drove a pickup truck to work
Over many nights he could not sleep
Only this and nothing more
She went by to pickup her son
To many times he would count over
They went shopping for Christmas
You can count him to pickup someone
They count so much they would sleep in his pickup
Nobody would play with Timmy
Trying to find the position location of each word
COLUMN B
Keyword List
Toe
Shoe
Count
Pumpkin
Pickup
Randy
Sally
Sleep
Jonathan
C2: =SUMPRODUCT((LEN($A$2:$A$12)-LEN(SUBSTITUTE((UPPER($A$2:$A$12)),UPPER(B2),"")))/LEN(B2))
D2&E2: =FILTER(B2:C10,C2:C10>0)
F2: =IF(E2="","",REPT(D2&"^",E2))
G2: =TEXTJOIN("",TRUE,F2:F4)
H2: =TRIM(MID(SUBSTITUTE($G$2,"^",REPT(" ",LEN($G$2))),(COUNTIF($H$1:H1,"<>&""")-1)*LEN($G$2)+1,LEN($G$2)))
I2: =IF(H2="","",IF(COUNTIF($H$2:H2,H2)>1,SUM(I1+1),1))
Try the below picture set up and formulas solution as in.
1] C2 "Total occurrence", formula copied down :
=SUMPRODUCT(LEN($A$2:$A$12)-LEN(SUBSTITUTE(LOWER($A$2:$A$12),LOWER(B2),"")))/LEN(B2)
2] D2 "Count", formula copied across to F2"Sleep" and all copied down :
=SUMPRODUCT(LEN($A2)-LEN(SUBSTITUTE(LOWER($A2),LOWER(D$1),"")))/LEN(D$1)
3] G2 "Keywords" , formula copied down:
=LOOKUP(ROW(A1),SUMIF(OFFSET(C$1,,,ROW($1:$12),),"<>")+1,B$2:B$4)&""
4] H2 "Occurrence", formula copied down:
=IF(G2="","",COUNTIF(G$2:G2,G2))
5] I2 "Content Keyword Data Text", formula copied down:
=IF(G2="","",LOOKUP(H2,SUMIF(OFFSET(INDEX($1:$1,MATCH(G2,$1:$1,0)),,,ROW($1:$12),),"<>")+1,$A$2:$A$12))
6] J2 "Position", formula copied down:
=IF(G2="","",FIND("~",SUBSTITUTE(LOWER(I2),LOWER(G2),"~",COUNTIFS(G$2:G2,G2,I$2:I2,I2))))

How to use VLOOKUP function in MS Excel

I am very very new to Excel
I have two sheets
Sheet 1
Country PMU Cluster
A Asia Mercury
B Australia Venus
C North America Jupiter
All the countries and continents are unique here
In sheet 2
I have
CountryCode Country PMU Cluster
123 A
234 A
453 B
235 C
1 country can have multiple codes
I have to take the PMU and Cluster and merge it with Sheet 2 , sheet 2 will have an additional column of Country Code.
Any help is very much apprciated.
Replacing my answer per your edits.
I'm just doing this on a single sheet but you can easily adapt by pointing to your other sheet for your lookup array.
Here is the formula for cell G2:
==VLOOKUP($F2,$A:$C,2,FALSE)
Here is the formula for cell H2:
=VLOOKUP($F2,$A:$C,3,FALSE)
Drag your formulas down and you're done. Vlookup formulas are very useful I recommend looking up how they work as someone else could better explain than I. Basically, you are looking up a value (column F) in an array (columns A,B,C) and returning a column index (B = 2, C = 3, etc) for a match. Lastly, you are looking for an approximate (TRUE) or exact (FALSE) match. Almost always use FALSE.
Also, look up cell references and how to lock them (ie, how $ signs rules vary). That way you can easily drag formulas across and keep your lookup value and array the same.

Splitting addresses into columns in Excel

I need help splitting addresses into columns in Excel.
Addresses in COLUMN A are written like:
601 W Houston St Abbott, TX 76621 United States
13498 US 301 South Riverview, FL 33578 United States
COLUMN B is actually a helper column. It contains only the city names from COLUMN A. My idea was to somehow match COLUMN B with COLUMN A and then all matches move to another column. That would separate City from the Address.State, Zip and Country I can use "split text to columns" since "comma" is delimiter. But I need help splitting address and the city.
There is a "comma" right after the city name, but some cities has more than one word in city name.
What I need to do is split the addresses like it's highlighted in green in the image below.
What is the best way to do that in Excel? What would be the formula for that?
We can use a quirk of LOOKUP to get this working.
=LOOKUP(1E+99,FIND(B$2:B$100,A2),B$2:B$100) in D2 will return the city based on searching for matches in column B. Note that this will need the full range of column B specified to be filled.
Then we can put =LEFT(A2,FIND(D2,A2)-2) in C2 to get the first part of the address.
The rest is easy if we can assume that the state, Zip and country are of constant length (if you've got any addressses outside the US then you'll need to alter this):
=LEFT(RIGHT(A2,22),3) in E2
=LEFT(RIGHT(A2,19),5) in F2
=RIGHT(A2,13) in G2
Since you already have City in Col B, just replace the city in A
D2 =SUBSTITUTE(A2,C2,"")
Column C Paste special values in Col C
Split Column C using comma.
Then split the Column D using "space". Assuming you have all records in US, you can add the country to all rows if required.
EDIT
I missed that the city name in the row does not correspond to the address. To match the city from the Master, you can use this array formula:
C2 =INDEX(B:B,MATCH(1,MATCH(""&$B:$B&"",A2,0),0))
Array formula must be confirmed with Ctrl-Shift-Enter.
However, this will find the first match. If you have cities Foster & Foster City in your master, Foster City wlll never be matched. So, sort the cities in descending order of length.
Once you have the City name matched you can follow the steps I gave earlier. Note that I have adjusted the formula to take into account the city name that has been matched by this new formula.
So, it is possible to get it done with the formula. It may not be the best way, but I got what I needed.
I've added a new sheet and named it "cities"
I moved the city list from sheet 1 to COL A in sheet "cities"
In sheet 1, B1 = =INDEX(cities!$A$1:$A$10000;LOOKUP(99^99;MATCH(RIGHT(TRIM(LEFT(SUBSTITUTE(A2;",";REPT(" ";255));255));ROW($A$1:$A$100));cities!$A$1:$A$10000;0)))
Then I've simply use SUBSTITUTE to remove city names from column A in Sheet 1: C1==SUBSTITUTE(A1, B1, "")
And that's it!

Excel look up value in array, return next value

I would like to look up a value in a range and return the value in the next row, but can't quite figure out how to do this. I especially would like to do this with formulas rather than VBA, and preferably with built-in formulas than custom (VBA) formulas, due to macro security issues.
I'm using Excel 2010. My workbook has two worksheets, "assessment" and "lookup". In lookup, I have lookup tables.
"lookup" looks something like:
Column A Column B Column C
1 Sales Engineering Manufacturing
2 Alice Bobbie Charlie
3 Dawn Edgar Frank
4 George Holly Isabel
In "assessment," I have some some drop downs from which users select one name from each column in "lookup." Based on some other criteria, I then rank these and create a new, sorted list (using INDEX() and MATCH()) that produce the selected name and corresponding column name a new sort order
Column A Column B
10 Engineering Edgar
11 Sales Alice
What I'd like is to return the name from the next row.
Column C
10 Holly
11 Dawn
But I'm having real trouble figuring out how to get there.
Assuming lookups is located at B2:D5 (change as required) and the result data is at F2:H3 (change as required) enter this formula in cell H2 then copy down.
=INDEX(
INDEX($B$2:$D$5,0,MATCH($F2,$B$2:$D$2,0)),
1+MATCH($G2,
INDEX($B$2:$D$5,0,MATCH($F2,$B$2:$D$2,0)),0))

Comparing Two Columns with Different Two Columns in same sheet and Hightlighting which is not matched

I am looking out to compare two columns “C and H” with “D and I” and return the specific rows in highlighted which are not matched with those two sets (which I call it as Failed)
Where column C and H contains name of the hotel and D and I contains the address of that particular hotel.
I don’t want those to be matched exactly, but if they both have a slight part of the content, its acceptable.
Example 1:
C1 contains - Hatta Fort Hotel
D1 contains - Hatta Oman Road
H1 column contains - Hatta Fort Hotel Dubai
I1 column contains - Old Dubai Abu Dhabi Road Dubai
In this case, I want to compare C1 and H1 and D1 and I1, and those two sets contains a part of the text, so it’s a Passed (in my words).
Example 2:
C2 contains - Hotel Arcobaleno
D2 contains - Provinciale
H2 contains - Hotel Arcobaleno
I2 contains - Contrada Taureana
In this case, If I compare C2 with H2 it matches, but if I compare D2 with I2 it does not, so I want this whole row to be highlighted with some color.
Is there any formula or macro for the same
Looking forward to hear a positive and helpful response.
Select columns C, D, H, and I (by using ctrl) and then apply this conditional format formula:
=AND($C1<>"",$D1<>"",$H1<>"",$I1<>"",NOT(AND(SUM(COUNTIF($H1,"*"&TRIM(MID(SUBSTITUTE($C1," ",REPT(" ",255)),255*(ROW(INDIRECT("1:"&LEN($C1)-LEN(SUBSTITUTE($C1," ",""))+1))-1)+1,255))&"*"))>0,SUM(COUNTIF($I1,"*"&TRIM(MID(SUBSTITUTE($D1," ",REPT(" ",255)),255*(ROW(INDIRECT("1:"&LEN($D1)-LEN(SUBSTITUTE($D1," ",""))+1))-1)+1,255))&"*"))>0)))
Example workbook here:
https://docs.google.com/file/d/0Bz-nM5djZBWYX0EwMk1GN1NjMmc/edit?usp=sharing

Resources