Selective Match/Vlookup (?) on Various Criteria in Single Row

m3ko

New Member
Joined
Apr 3, 2024
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
Hello everyone,
If you can, I am hoping for some help here.
I tried looking for solutions already but haven't found what I need yet - will still look anyway.
Sort of relevant but not quite:
(Vlookup - Find partial match from the lookup_value)

Anyway, my current roadblock:
I have exported some data from our system. It contains a list of addresses for each of our customers.
However, the data is a bit scattered, with the address being separated into a few columns and not all in the same format.
I'm hoping to add a new column with the Province Code for each of the address.
The problem is that, as mentioned, the address date isn't all uniform. Some have the full address with the province names, some just have the abbreviated province names, and, others just the city.
I tried to create a LookUp table containing the different variations of city names, province name shorthand and the correct corresponding Province Code.
But I am unable to get it to just "match" up and populate the right Province Code.
In my LookUp table, I am hoping to have all the city variations in the same row as the Prov. code I want to use.
Hope this makes sense and thank you so much in advance for all the help.
Let me know if there are already solutions to this that I haven't found yet.

Thank you.



Sales Report 2019 to 2024-10 with Province.State Field.xlsx
VWXYZAAAB
3Combined AddressCity VariationsProv.
4MALLAIG, ALBERTA,T0A 2K0, #N/AALBERTA, AB, A.B.AB
5ABBOTSFORD, BC V2T 0C4, , , #N/ABRITISH COLUMBIA, BC, B.C.BC
6RED DEER COUNTRY, AB,T4E 0C6, MANITOBA, MB, M.B.MB
7LANGLEY, BC V1M 0A9, , NEW BRUNSWICK, NB, N.B.NB
8ST-BRUNO, QC J3V 6B9, , , NEWFOUNDLAND, NL, N.L.NL
9REGINA, SK,S4N 5P7, , NORTHWEST TERRITORIES, NT, N.T.NT
10ABBOTSFORD, BC,V2T 6J8, , NOVA SCOTIA, NS, N.S.NS
11GARIBALDI HIGHLANDS, B.C.,V0N 1T0, , NUNAVUT, NU, N.U.NU
12CHIBOUGAMAU, QUEBEC,G8P 2Z8, , ONTARIO, ON, O.N.ON
13NOTRE-DAME-DES-MONTS, QUEBEC, ,G0T 1L0PRINCE EDWARD ISLAND, PE, P.E.PE
14BOX 517,SLAVE LAKE, AB,T0G 2A0QUEBEC, QC, Q.C., PQQC
15JOLIETTE, QC, ,J6E 2S4SASKATCHEWAN, SK, S.K.SK
16MERRITT, B.C.,V1K 1C2, , YUKON, YT, Y.T.YT
Customer Province XRef-unlinked
Cell Formulas
RangeFormula
Y4Y4=INDEX(Table5[[#All],[Prov.]], MATCH(V4, Table5[[#All],[City Variations]], 0))
Y5Y5=INDEX(Table5[[#All],[Prov.]], MATCH(V22, Table5[[#All],[City Variations]], 0))
V4:V16V4=TEXTJOIN(",",TRUE,SALESDATACANADA89[@[SoldToAddr2]:[SoldToAddr4]])


EDIT:
Sorry, I should add that I already combined all the scattered address data into one line - used the "TEXTJOIN" formula. Not sure if this will affect anything of if I should avoid using this.

Thank you
 
Last edited by a moderator:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I'm hoping to add a new column with the Province Code for each of the address.
The problem is that, as mentioned, the address date isn't all uniform. Some have the full address with the province names, some just have the abbreviated province names, and, others just the city.
I tried to create a LookUp table containing the different variations of city names, province name shorthand and the correct corresponding Province Code.
But I am unable to get it to just "match" up and populate the right Province Code.
In my LookUp table, I am hoping to have all the city variations in the same row as the Prov. code I want to use.
Assuming your Province names in the source data are in a single column, you can add a helper column to clean and replace the old value with a new value.

I tried a sample test using XLOOKUP to see if this will help...

I'm using the LET function to both TRIM the Lookup Value, and the Lookup Array just incase there are any spaces before or after your source data. I added some in the sample data to confirm it will work. However, that doesn't mean that your source data may not have other discrepencies. However, using the helper column will help you find them so they can be corrected.

The LEFT Table is the Source Data containing your current Province name (old) and the Helper column (New) where you use the formula to both cleanup the OLD value and return the new value from the Replace column in the RIGHT Table... which is the Table you need to create to list your Find & Replace values.

The RIGHT Table should not have any discrepencies. It should have exactly what you want to FIND and what to REPLACE with. To make sure, just use an empty column to the right of the table to make sure; then Copy/Paste Values only over the FIND column. Just make sure your Tables and Column Headers are named how you need them.
Excel Formula:
=TRIM(t_Find_Replace[@Find])

VBA Testing.xlsm
ABCDE
1Province OLDProvince NEWFindReplace
2ALBERTAABALBERTAAB
3 ABABABAB
4 A.B.ABA.B.AB
5BRITISH COLUMBIABCBRITISH COLUMBIABC
6 BCBCBCBC
7 B.C.BCB.C.BC
REPLACE
Cell Formulas
RangeFormula
B2:B7B2=LET( Old, TRIM([@[Province OLD]]), Find, TRIM(t_Find_Replace[Find]), TRIM(XLOOKUP(Old,Find,t_Find_Replace[Replace])))
 
Upvote 0
Solution
Thanks Zero,

Have been away and haven't had a chance to try this out. It looks like what I need though!

Thanks so much!

Cheers mate!
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top