How to compare data on differerent excel spreadsheets

hchristian

New Member
Joined
Aug 12, 2011
Messages
1
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true" DefSemiHidden="true" DefQFormat="false" DefPriority="99" LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" Priority="39" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" Name="toc 9"/> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> <w:LsdException Locked="false" Priority="10" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" Priority="11" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" Priority="22" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="59" SemiHidden="false" UnhideWhenUsed="false" Name="Table Grid"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="0" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> <w:LsdException Locked="false" Priority="34" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;} </style> <![endif]--> Dear Forum Members:


I use Excel 2007.


I research government records and compile Excel lists of dormant assets. I also receive lists of dormant assets from government agencies in Excel, often 25,000 lines or more.

I maintain a client list in Excel.

I then manually sort and review each Excel spreadsheet and manually compare it to my list of clients to identify potential recoveries. Very time consuming and lots of margin for error. Recent clients have hundreds of subsidiaries making this task nearly impossible.

I would like to automate this process (perhaps a macro) so that I can query individual Excel spreadsheet of dormant assets against my list of existing clients – and extrapolate those which match into a new spreadsheet.


The query needs to be a bit "fuzzy" to return matches, as the name is not always precise on the government lists. "A. B. Jones Asphalt" on my client list may be listed as "Jones Asphalt, A B" on the government list.


Any assistance would be a blessing! Thank you in advance.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi, Welcome to the board :)

One of he most efficient approaches may be to 'Normalise' the company name and then store it as a key in a Dictionary object.

By 'Normalise' I mean convert to uppercase, replace all non alphanumerics with spaces and then remove multiple spaces
So 'A.B. Jones Asphalt' would be stored as 'A B JONES ASPHALT' (which comprises 4 'words')

for the matching process we can then normalise each dormant asset name and then try to match each word permutation against our dictionary object. So, the code would try to match all 24 combinations of 'A' 'B' 'JONES' and 'ASPHALT' against the dictionary (or until it found a match).

Sounds easy eh?

That said, an 8-word name would generate over 40,000 permutations for the code to check :¬/

I would need data layouts of each of the spreadsheet before writing the macro of course.
 
Upvote 0
Perhaps a neater (& quicker) twist to this would be to just sort the words alphabetically before comparing, so, for example, it would store the name 'A.B'Jones, Asphalt' as 'A ASHPHALT B JONES'. No need for Permutations processing then.
 
Upvote 0
Hi, Try this 'GetDormantAssets' macro:
Code:
Option Explicit
Const msExistingSheetName As String = "Sheet1"
Const msExistingNameColumn As String = "A"

Const msDormantSheetName As String = "Sheet1"
Const msDormantNameColumn As String = "A"

Const msResultsSheetName As String = "Sheet3"

Const mlExistingStartDataRow As Long = 2
Const mlDormantStartDataRow As Long = 2

Sub GetDormantAssets()
Dim bError As Boolean
Dim lRow As Long
Dim lResultsRow As Long
Dim objNamesDictionary As Object
Dim rCur As Range
Dim sCurName As String
Dim vFile As Variant
Dim wbDormant As Workbook
Dim wsDormant As Worksheet
Dim wsExisting As Worksheet
Dim wsResults As Worksheet

bError = False
Set wsExisting = Nothing
On Error Resume Next
Set wsExisting = ThisWorkbook.Sheets(msExistingSheetName)
On Error GoTo 0
If wsExisting Is Nothing Then
    MsgBox prompt:="Error accessing sheet '" & msExistingSheetName & "'" & vbCrLf & Err.Description, _
            Buttons:=vbOKOnly + vbCritical
    bError = True
End If

If bError = False Then
    vFile = Application.GetOpenFilename(filefilter:="Excel Files (*.xls*), *.xls*", _
                                      Title:="Please select Input Dormant File to be searched")
    If vFile = False Then
        MsgBox prompt:="Macro abandoned at user request", _
                Buttons:=vbOKOnly + vbInformation
        bError = True
    End If
End If

If bError = False Then
    Set wbDormant = Nothing
    On Error Resume Next
    Set wbDormant = Workbooks.Open(Filename:=vFile, ReadOnly:=True)
    On Error GoTo 0
    If wbDormant Is Nothing Then
        MsgBox prompt:="Unable to open file:" & vbCrLf & CStr(vFile) & vbCrLf & Err.Description, _
                Buttons:=vbCritical + vbOKOnly, _
                Title:="Error opening Dormant File"
        bError = True
    Else
        Set wsDormant = Nothing
        On Error Resume Next
        Set wsDormant = wbDormant.Sheets(msDormantSheetName)
        On Error GoTo 0
        If wsDormant Is Nothing Then
            MsgBox prompt:="Unable to open sheet '" & msDormantSheetName & "' from Dormant file" & vbCrLf & _
                            Err.Description, _
                    Buttons:=vbOKOnly + vbCritical, _
                    Title:="Error accessing Dormant file sheet"
            bError = True
        End If
    End If
End If

'-- Set up Names Dictionary  --
If bError = False Then
    
    Set objNamesDictionary = Nothing
    Set objNamesDictionary = CreateObject("Scripting.Dictionary")
    
    lRow = wsExisting.Cells(Rows.Count, msExistingNameColumn).End(xlUp).Row
    If lRow > 1 Then
        For Each rCur In wsExisting.Range(msExistingNameColumn & "2:" & msExistingNameColumn & lRow)
            sCurName = CStr(rCur.Value)
            On Error Resume Next
            objNamesDictionary.Add Key:=NormaliseName(sCurName), Item:=sCurName
            On Error GoTo 0
        Next rCur
    End If
    
End If

If bError = False Then
    Set wsResults = ThisWorkbook.Sheets(msResultsSheetName)
    wsResults.UsedRange.ClearContents
    wsResults.Range("A1").Value = "Name"
    lResultsRow = 1
    
    lRow = wsDormant.Cells(Rows.Count, msDormantNameColumn).End(xlUp).Row
    If lRow > 1 Then
        For Each rCur In wsDormant.Range(msDormantNameColumn & "2:" & msDormantNameColumn & lRow)
            sCurName = Trim$(CStr(rCur.Value))
            If sCurName <> "" Then
                If objNamesDictionary.exists(NormaliseName(sCurName)) Then
                    lResultsRow = lResultsRow + 1
                    wsResults.Cells(lResultsRow, 1).Value = sCurName
                End If
            End If
        Next rCur
    End If
End If

On Error Resume Next
objNamesDictionary.RemoveAll
Set objNamesDictionary = Nothing
wbDormant.Close

End Sub

Function NormaliseName(ByVal Stringx As String) As String
Dim lPtr As Long, lPtr1 As Long
Dim sCur As String, sResult As String
Dim saResult() As String

'-- replace anything other than A to Z, 0 to 9 or apostrophe with a space, and convert to uppercase
sResult = Stringx
For lPtr = 1 To Len(sResult)
    sCur = UCase$(Mid$(sResult, lPtr, 1))
    If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ'0123456789", sCur) = 0 Then sCur = " "
    Mid$(sResult, lPtr, 1) = sCur
Next lPtr

sResult = WorksheetFunction.Trim(Stringx)       ' remove leading, trailing & intermediate multiple spaces

'-- Now sort the result --
If sResult <> "" Then
    saResult = Split(WorksheetFunction.Trim(sResult), " ")
    For lPtr = 0 To UBound(saResult) - 1
        sCur = saResult(lPtr)
        For lPtr1 = lPtr + 1 To UBound(saResult)
            
            If sCur > saResult(lPtr1) Then
                saResult(lPtr) = saResult(lPtr1)
                saResult(lPtr1) = sCur
                sCur = saResult(lPtr)
            End If
        Next lPtr1
    Next lPtr
    sResult = Join(saResult, " ")
End If

NormaliseName = sResult
End Function
The macro assumes that the names in both the Existing Client list & dormant file are in Sheet1, column A, and start in row 2
You are prompted for the input Dormant file, and the output is placed in sheet3
 
Upvote 0
Try this version - it actually works, which is a bonus :???:
Code:
Option Explicit
Const msExistingSheetName As String = "Sheet1"
Const msExistingNameColumn As String = "A"

Const msDormantSheetName As String = "Sheet1"
Const msDormantNameColumn As String = "A"

Const msResultsSheetName As String = "Sheet3"

Const mlExistingStartDataRow As Long = 2
Const mlDormantStartDataRow As Long = 2

Sub GetDormantAssets()
Dim bError As Boolean
Dim lRow As Long
Dim lResultsRow As Long
Dim objNamesDictionary As Object
Dim rCur As Range
Dim sCurName As String
Dim vFile As Variant
Dim wbDormant As Workbook
Dim wsDormant As Worksheet
Dim wsExisting As Worksheet
Dim wsResults As Worksheet

bError = False
Set wsExisting = Nothing
On Error Resume Next
Set wsExisting = ThisWorkbook.Sheets(msExistingSheetName)
On Error GoTo 0
If wsExisting Is Nothing Then
    MsgBox prompt:="Error accessing sheet '" & msExistingSheetName & "'" & vbCrLf & Err.Description, _
            Buttons:=vbOKOnly + vbCritical
    bError = True
End If

If bError = False Then
    vFile = Application.GetOpenFilename(filefilter:="Excel Files (*.xls*), *.xls*", _
                                      Title:="Please select Input Dormant File to be searched")
    If vFile = False Then
        MsgBox prompt:="Macro abandoned at user request", _
                Buttons:=vbOKOnly + vbInformation
        bError = True
    End If
End If

If bError = False Then
    Set wbDormant = Nothing
    On Error Resume Next
    Set wbDormant = Workbooks.Open(Filename:=vFile, ReadOnly:=True)
    On Error GoTo 0
    If wbDormant Is Nothing Then
        MsgBox prompt:="Unable to open file:" & vbCrLf & CStr(vFile) & vbCrLf & Err.Description, _
                Buttons:=vbCritical + vbOKOnly, _
                Title:="Error opening Dormant File"
        bError = True
    Else
        Set wsDormant = Nothing
        On Error Resume Next
        Set wsDormant = wbDormant.Sheets(msDormantSheetName)
        On Error GoTo 0
        If wsDormant Is Nothing Then
            MsgBox prompt:="Unable to open sheet '" & msDormantSheetName & "' from Dormant file" & vbCrLf & _
                            Err.Description, _
                    Buttons:=vbOKOnly + vbCritical, _
                    Title:="Error accessing Dormant file sheet"
            bError = True
        End If
    End If
End If

'-- Set up Names Dictionary  --
If bError = False Then
    
    Set objNamesDictionary = Nothing
    Set objNamesDictionary = CreateObject("Scripting.Dictionary")
    
    lRow = wsExisting.Cells(Rows.Count, msExistingNameColumn).End(xlUp).Row
    If lRow > 1 Then
        For Each rCur In wsExisting.Range(msExistingNameColumn & "2:" & msExistingNameColumn & lRow)
            sCurName = CStr(rCur.Value)
            On Error Resume Next
            objNamesDictionary.Add Key:=NormaliseName(sCurName), Item:=sCurName
            On Error GoTo 0
        Next rCur
    End If
    
End If

If bError = False Then
    Set wsResults = ThisWorkbook.Sheets(msResultsSheetName)
    wsResults.UsedRange.ClearContents
    wsResults.Range("A1").Value = "Name"
    lResultsRow = 1
    
    lRow = wsDormant.Cells(Rows.Count, msDormantNameColumn).End(xlUp).Row
    If lRow > 1 Then
        For Each rCur In wsDormant.Range(msDormantNameColumn & "2:" & msDormantNameColumn & lRow)
            sCurName = Trim$(CStr(rCur.Value))
            If sCurName <> "" Then
                If objNamesDictionary.exists(NormaliseName(sCurName)) Then
                    lResultsRow = lResultsRow + 1
                    wsResults.Cells(lResultsRow, 1).Value = sCurName
                End If
            End If
        Next rCur
    End If
End If

On Error Resume Next
objNamesDictionary.RemoveAll
Set objNamesDictionary = Nothing
wbDormant.Close

End Sub

Function NormaliseName(ByVal Stringx As String) As String
Dim lPtr As Long, lPtr1 As Long
Dim sCur As String, sResult As String
Dim saResult() As String

'-- replace anything other than A to Z, 0 to 9 or apostrophe with a space, and convert to uppercase
sResult = Stringx
For lPtr = 1 To Len(sResult)
    sCur = UCase$(Mid$(sResult, lPtr, 1))
    If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ'0123456789", sCur) = 0 Then sCur = " "
    Mid$(sResult, lPtr, 1) = sCur
Next lPtr

sResult = WorksheetFunction.Trim(sResult)       ' remove leading, trailing & intermediate multiple spaces

'-- Now sort the result --
If sResult <> "" Then
    saResult = Split(sResult, " ")
    For lPtr = 0 To UBound(saResult) - 1
        sCur = saResult(lPtr)
        For lPtr1 = lPtr + 1 To UBound(saResult)
            
            If sCur > saResult(lPtr1) Then
                saResult(lPtr) = saResult(lPtr1)
                saResult(lPtr1) = sCur
                sCur = saResult(lPtr)
            End If
        Next lPtr1
    Next lPtr
    sResult = Join(saResult, " ")
End If

NormaliseName = sResult
End Function
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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