Find and Replace based upon an array or similar

Imrhien

New Member
Joined
May 5, 2011
Messages
27
G'day folks!

The people here have been a massive help with getting my macro working. I'm down to the last part of it now.

The situation: I regularly upload address databases to my shipping system. Unfortunately, the shipping system is quite precise about what suburb/town combinations I can use. One example is:
Town: Auckland
Suburb: Green bay

My software expects:
Town: Waitakere
Suburb: Green Bay

Because of a recent change in the addressing in Auckland, most address databases I upload will have the former address, which won't validate.

So what I want to do is get excel to search through the SUBURB column and replace the neighbouring TOWN cell with an appropriate value. I have a spreadsheet right now with all the combinations the shipping software will accept. In this case it's acceptable to assume that the SUBURB data is correct. If there are SUBURBs that exist in two TOWNS, I have deleted those references from the Combinations spreadsheet so that it's impossible to accidentally assign the wrong TOWN. Spelling mistakes and duplicate suburbs can be fixed manually when uploading the data, so that's not a priority. This is basically a brute attempt to purify the data as much as possible and reduce manual work.

So I'm guessing that I need to somehow put the TOWN and SUBURB data into a big 2d array, and then create a FIND/REPLACE loop that will roll through the suburb column, find matches in the SUBURB array and replace the neighbouring TOWN cell with the suburb's associated town value.

Here's my current code for reference. Yes, it's awful :biggrin:

Code:
Columns("K:K").Select
    Do
        'North Shore Fixes
        If UCase(ActiveCell.Value) = "ALBANY" Then
        ActiveCell.Offset(0, -1).Value = "North Shore City"
        End If
        If UCase(ActiveCell.Value) = "TAKAPUNA" Then
        ActiveCell.Offset(0, -1).Value = "North Shore City"
        End If
        If UCase(ActiveCell.Value) = "MAIRANGI BAY" Then
        ActiveCell.Offset(0, -1).Value = "North Shore City"
        End If
    
        ActiveCell.Offset(1, 0).Select

    Loop Until IsEmpty(ActiveCell.Offset(0, 2))

Can anyone offer any advice? I know I'm asking a lot here.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I just need to find a way to start...I can't figure out how to import my data into the array for starters!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,853
Members
452,948
Latest member
UsmanAli786

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