+ Reply to Thread
Results 1 to 5 of 5

Matching text between arrays to find a related number

Hybrid View

  1. #1
    Registered User
    Join Date
    05-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    69

    Matching text between arrays to find a related number

    Hi guys,

    I'm trying to match Utility IDs w/ corresponding names on one sheet to the same Utility Names on another sheet and carry the UID over. The problem is that the names, while they are the same in a sense, are displayed differently at times (ex: AEP Texas Central Co. = AEP Texas Central Company)

    See attached file for reference.

    What I want to do is have the Utility ID's that are on the UIDs sheet "find their match" on the IOU sheet. The utilities found on IOU sheet may or may not be on the UIDs sheet. My end goal is to get the corresponding UIDs to the IOU page.


    Link to excel file: https://www.dropbox.com/s/3loomq5lb988lx6/IOU1.xlsx?dl=0
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Matching text between arrays to find a related number

    Hasta Manana
    Last edited by xladept; 09-16-2014 at 11:36 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Matching text between arrays to find a related number

    Hi,

    There is a companion function to this which I've grown tired of editing, it's slow but at this point it finds 128 matches

    Sub BGreeson(): Dim wi As Worksheet, wu As Worksheet, IOU As String, UID As String
    Dim i As Long, u As Long, OU, ID, o As Long, d As Long
    Set wi = Sheets("IOU"): Set wu = Sheets("UIDs")
    For i = 2 To wi.Range("B" & Rows.Count).End(xlUp).Row
           
                    IOU = Rep(wi.Range("B" & i))
                    OU = Split(IOU, " ")
            For u = 2 To wu.Range("B" & Rows.Count).End(xlUp).Row
             
                If wu.Range("C" & u) = "*" Then GoTo GetAnother
                UID = Rep(wu.Range("B" & u))
                        ID = Split(UID, " ")
                If UBound(ID) = UBound(OU) Then
    If Replace(wi.Range("B" & i), ",", "") = Replace(wu.Range("B" & u), ",", "") Then
                GoSub StampIt: GoTo GetNext: End If
                For o = LBound(OU) To UBound(OU)
                For d = LBound(ID) To UBound(ID)
                If Trim(LCase(OU(o))) = Trim(LCase(ID(d))) Then GoTo Nexto
                Next d
                GoTo GetAnother
    Nexto:      Next o
                GoSub StampIt: GoTo GetNext
            End If
    GetAnother: Next u
    GetNext: Next i: wu.Range("C:C").ClearContents
    Exit Sub
    StampIt: wi.Range("K" & i) = wu.Range("A" & u): wu.Range("C" & u) = "*": Return
    End Sub
    Function Rep(S As String) As String
    Dim Wot, Wit, i As Integer
    Wot = Array("Corporation", "Company", "Limited", "Incorporated", "City of", "Capital Inc", "Electric", _
    "Public", "Services", "Service", "Of", "-", "New York")
    Wit = Array("Corp", "Co", "Ltd", "Inc", "", "", "Elec", "Pub", "Serv", "Serv", "", " ", "NY")
    S = Replace(Replace(Trim(S), ",", ""), ".", "") 'knock off commas and periods
    For i = LBound(Wot) To UBound(Wot)
    S = Replace(S, Wot(i), Wit(i))
    Next i
    Rep = Trim(S)
    End Function
    Last edited by xladept; 09-17-2014 at 07:25 PM.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Matching text between arrays to find a related number

    I've edited the function and now with this function it gets 140:

    Function Rep(S As String) As String
    Dim Wot, Wit, Wff, i As Integer
    Wff = Array(".", ",", "Incorporated", "Inc", "Limited", "Ltd", "Corp", "Corporation", _
    "City of", "Capital Inc", "Illuminating", "Illum", "LLC", "Of")
    For i = LBound(Wff) To UBound(Wff): S = Replace(S, Wff(i), ""): Next i
    
    Wot = Array("Company", "Electric", "Public", "Services", "Service", "-", _
    "New York", "&", "  ", "and", "Mount")
    Wit = Array("Co", "Elec", "Pub", "Serv", "Serv", " ", "NY", " & ", " ", "&", "Mt")
    For i = LBound(Wot) To UBound(Wot): S = Replace(S, Wot(i), Wit(i)): Next i
    
    Rep = Trim(S): End Function

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Matching text between arrays to find a related number

    Here's a quick routine that gets the same 140

    Function Rep(S As String) As String
    Dim Wot, Wit, Wff, i As Integer
    Wff = Array(".", ",", "Incorporated", "Inc", "Limited", "Ltd", "Corp", "Corporation", _
    "City of", "Capital Inc", "Illuminating", "Illum", "LLC", "Of")
    For i = LBound(Wff) To UBound(Wff): S = Replace(S, Wff(i), ""): Next i
    
    Wot = Array("Company", "Electric", "Public", "Services", "Service", "-", _
    "New York", "&", "  ", "and", "Mount")
    Wit = Array("Co", "Elec", "Pub", "Serv", "Serv", " ", "NY", " & ", " ", "&", "Mt")
    For i = LBound(Wot) To UBound(Wot): S = Replace(S, Wot(i), Wit(i)): Next i
    
    Rep = Trim(S): End Function
    
    
    Sub BGreesonQwk(): Dim wi As Worksheet, wu As Worksheet, IOU As String, UID As String
    Dim i As Long, u As Long, OU, ID, o As Long, D As Long
    Set wi = Sheets("IOU"): Set wu = Sheets("UIDs")
    
        With CreateObject("Scripting.Dictionary")
            For u = 2 To wu.Range("B" & Rows.Count).End(xlUp).Row
        UID = LCase(Rep(wu.Range("B" & u))): .Item(UID) = wu.Range("A" & u): Next u
        
        For i = 2 To wi.Range("B" & Rows.Count).End(xlUp).Row
                IOU = LCase(Rep(wi.Range("B" & i)))
        If .Exists(IOU) Then wi.Range("K" & i) = .Item(IOU)
        Next i:    End With
    End Sub
    * it's the same function

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find Matching text in table and add number in that row
    By james19 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-26-2014, 11:39 AM
  2. [SOLVED] Total number of matching numbers from 2 arrays
    By williamspage in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-22-2013, 10:19 AM
  3. [SOLVED] Find matching number from 2 sheets and combine related data
    By downtown1933 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-26-2013, 05:46 PM
  4. [SOLVED] Find match, find related cell and return that number
    By HelpHelpHelp in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-17-2012, 06:46 AM
  5. [SOLVED] How to find all unique, matching values betwen two arrays of cells
    By exmonkey in forum Excel General
    Replies: 11
    Last Post: 06-20-2012, 05:47 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1