VBA: Search for Text strings and return value from table

ChetManley

New Member
Joined
Dec 9, 2019
Messages
33
Office Version
  1. 2010
Platform
  1. Windows
Hi all,

Long time lurker, first time poster - let me thank you all for years of troubleshooting and learning with pro's how to be a bit better in Excel.

My question is around VBA - not very well versed in it - and will try to explain as best as I can.

I have a list of countries with a score against each country, let's call it "Countries" table.
I also have a list of customers with multiple columns for address, nationality, etc that all revolve around location, let's call this table "Customers".

What I would like to learn how to do (if possible) is to:

Run a VBA code to search each relevant column in the "Customers" table for the countries in the "Countries" table and return the country score for each respective customer on a separate table, let's call this one "Customer Score".

Is this possible at all? Or am I better off using formulas? Issue is I will have to do this on a quarterly basis and I'd like to make it as resilient as possible (in case of absence)..

Much appreciated,
Chet
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi @DanteAmor replaced with generic data - attached as picture.

The idea would be to return the result onto the Customer Score table.

Apologies for using screenshots - currently not on my machine and I can't install the add-on at the moment.
 

Attachments

  • Country.jpg
    Country.jpg
    37.5 KB · Views: 19
  • Customer Score.jpg
    Customer Score.jpg
    36.1 KB · Views: 21
  • Customer.jpg
    Customer.jpg
    36.6 KB · Views: 18
Upvote 0
The images are very small and do not look good.
The customer score table is empty, you could fill it with the sample data and explain how to fill it.
Reduce the number of examples to make the image clearer.
 
Upvote 0
Hi @DanteAmor sorry about that.
The crux of the problem is that I have a list of every country in the world with a rating against them - e.g.

CountryRating
AlbaniaHigh
ArgentinaHigh
AndorraMedium
AustraliaLow
AustriaLow
AzerbaijanHigh

And on the other side I have a customer list with their profiles (can be multiple for the same person) and their addresses, e.g.

Customer No.Country of Nationality AddressLine 1AddressLine 2AddressLine 3AddressLine 4AddressLine 5
123ArgentinaXYZ123Buenos AiresArgentina
123Argentina444WienWien, Austria
123Australia215QWERTY12345Perth, Australia
345AlbaniaZXCV12345SydneyAustralia
567AustriaAndorra444, Andorra
100AndorraQWERTYAzerbaijanBaku222333

My goal is to use the country rating list to rate customers based on their address and nationality and return the highest rating (from all the above fields) to fill a table similar to the below:

Customer No.Rating
123High
123High
123Low
345High
567Medium
100High

Hope this makes it easier to follow? I am oversimplifying because my original data set has dozens more columns and thousands of customers, but if you can point the way I can probably extrapolate.
The way I am thinking to approach this is not very sophisticated - something like searching for the particular strings in the multiple fields I have with address data (albeit I don't know if possible).

Any help anyone can provide will be immense as I am stuck in this for a week now...

Many thanks
Chet
 
Upvote 0
Could you explain the following example?
How, with only the number 123, can you identify if the customer is from Argentina or is from Australia?

Book1
AB
1Customer No.Rating
2123High
3123High
4123Low
Sheet3
 
Upvote 0
Could you explain the following example?
How, with only the number 123, can you identify if the customer is from Argentina or is from Australia?

Book1
AB
1Customer No.Rating
2123High
3123High
4123Low
Sheet3

You can't - because in most cases in my scenario the customers are companies and sometimes they have multiple accounts from different jurisdictions.
Which I circumvented by listing every single customer account - i.e. if customer 123 has 4 accounts, I will list them and aim to bring in the 4 respective jurisdictions - hope this helps?
 
Upvote 0
Could you have something like this in your results sheet in columns A and B. And that the formula or macro fill column C?

Book1
ABC
1Customer No.CountryRating
2123ArgentinaHigh
3123ArgentinaHigh
4123AutraliaLow
5345AlbaniaHigh
6567AustriaMedium
7100AndorraHigh
Sheet3
 
Upvote 0
Could you have something like this in your results sheet in columns A and B. And that the formula or macro fill column C?

Book1
ABC
1Customer No.CountryRating
2123ArgentinaHigh
3123ArgentinaHigh
4123AutraliaLow
5345AlbaniaHigh
6567AustriaMedium
7100AndorraHigh
Sheet3

Yes that would work ?
 
Upvote 0
Not sure if this can help you.
If on Sheet 3 you have the country, then the customer number is not necessary, check the following:

Book1
AB
1CountryRating
2AlbaniaHigh
3ArgentinaHigh
4AndorraMedium
5AutraliaLow
6AustriaLow
7AzerbaijanHigh
Sheet1



Book1
ABC
1Customer No.CountryRating
2123ArgentinaHigh
3123ArgentinaHigh
4123AutraliaLow
5345AlbaniaHigh
6567AustriaLow
7100AndorraMedium
Sheet3
Cell Formulas
RangeFormula
C2:C7C2=VLOOKUP(B2,Sheet1!$A$1:$B$7,2,0)
 
Upvote 0

Forum statistics

Threads
1,215,748
Messages
6,126,654
Members
449,326
Latest member
asp123

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