I have two excel spreadsheets that list peoples names in different formats.
One sheet lists the names formatted as "First Last", organizes the names by department, and does not list their ID number.
The other sheet lists the names formatted as "Last, First", organizes them alphabetically, does not show their department, and shows their ID number.
What I need to accomplish is to pull the names and ID numbers of people from specific departments. Rearranging the First and Last names to match hasn't been an issue. The issue that I am having is that sometimes the names do not match.
For example: Sheet 1 lists the name as "John Smith" Sheet 2 lists the name as "Smith Jr, John"
In this example I would search sheet 2 for "Smith, John" and yield no results.
Unfortunately these sheets are managed by other people so I cannot make edits to the sheets.
Here I split the name from sheet 1 and format it like sheet 2.
Dim nameTemp() As String = Split(CType(curSheet.Range("J" & xlRow).Value, String))
name = Trim(nameTemp(1)) + ", " + Trim(nameTemp(0))
Here I look in the second sheet for matches. This misses any names that have Jr, III, II etc. listed in the second sheet but not the first.
idRange = curSheet.UsedRange.Find(What:=name, LookAt:=XlLookAt.xlPart)
What I've been searching for is a way to search for cells that contain both the substrings:
nameTemp(0) and nameTemp(1)
Using the UsedRange.Find method if at all possible.
I've tried:
idRange = curSheet.UsedRange.Find(What:=(nameTemp(0) And nameTemp(1)), LookAt:=XlLookAt.xlPart)
And
idRange = curSheet.UsedRange.Find(What:=nameTemp(0)What:=nameTemp(1), LookAt:=XlLookAt.xlPart)
And other scenarios that I did not document.
Not Nothing
. However, you'll have problems with inconsistent text etc. – SJR