Hello Everyone,
I have a limited CRM that will produce two lists, producers and clients, in a contiguous format but the data does not show which producer wrote which client. To solve this I have another report(from the CRM) that is only available by printing it to a .PDF file and then extracting it to excel so the format is horrible. I am writing a program that will search this report and find the producers and their clients in the document and then copy them into a new sheet showing the one to many relationship of the producer to client. The final product should look like the following:
Cell1 Cell2 Cell3 Cell4 Cell5 Cell6
PFirst PMiddle PLast CFirst CMiddle CLast
John A Dowe Jack J Anders
John A Dowe Paul C Johnson
Allen T Hawkins Amy P Andrews
Allen T Hawkins John J Baker
Allen T Hawkins Dawn G Jones
Anyway, the code I have below has been cut and pasted in and developed from trial and error to pull out the producers and parse their names in to the three cells I am looking for. Now I am moving on to adding the clients to these producers and I have run into two problems.
PROBLEM 1: The producers and clients do not always follow the same name pattern. Generally the producer will follow "Producer: "First MiddleInitial Last" pattern and the client "First MiddleInitial Last" pattern but there are cases where both the producer and the client do not have Middle Initials.
PROBLEM 2: The relationship between the producer and the client is one to many and the report list the producer once and then lists the clients below. I need to list the producer once for each occurrence of their clients in the new sheet.
If anyone can give me a hand with this I would greatly appreciate it. My code is below.
Thanks in Advance!
pcdaugs
I have a limited CRM that will produce two lists, producers and clients, in a contiguous format but the data does not show which producer wrote which client. To solve this I have another report(from the CRM) that is only available by printing it to a .PDF file and then extracting it to excel so the format is horrible. I am writing a program that will search this report and find the producers and their clients in the document and then copy them into a new sheet showing the one to many relationship of the producer to client. The final product should look like the following:
Cell1 Cell2 Cell3 Cell4 Cell5 Cell6
PFirst PMiddle PLast CFirst CMiddle CLast
John A Dowe Jack J Anders
John A Dowe Paul C Johnson
Allen T Hawkins Amy P Andrews
Allen T Hawkins John J Baker
Allen T Hawkins Dawn G Jones
Anyway, the code I have below has been cut and pasted in and developed from trial and error to pull out the producers and parse their names in to the three cells I am looking for. Now I am moving on to adding the clients to these producers and I have run into two problems.
PROBLEM 1: The producers and clients do not always follow the same name pattern. Generally the producer will follow "Producer: "First MiddleInitial Last" pattern and the client "First MiddleInitial Last" pattern but there are cases where both the producer and the client do not have Middle Initials.
PROBLEM 2: The relationship between the producer and the client is one to many and the report list the producer once and then lists the clients below. I need to list the producer once for each occurrence of their clients in the new sheet.
If anyone can give me a hand with this I would greatly appreciate it. My code is below.
Thanks in Advance!
pcdaugs
Code:
Sub FindProducerClient()
Dim rFndP1 As Excel.Range ' Producer found range of Sheet2
Dim rFndP2 As Excel.Range ' Next Producer found range of Sheet2
Dim rFndC As Excel.Range ' Client found range of Sheet2
Dim sAdr As String ' Address of first found cell
Dim astr1() As String ' Zero-based parsing buffer for rFndP1
Dim astr2() As String ' Zero-based parsing buffer for rFndC
Dim rOut As Excel.Range ' Output range on Sheet1
'Clear output sheet and write header
Sheet1.Cells.ClearContents
Sheet1.Range("A1").Resize(, 6) = Array("ProducerFN", "ProducerMI", "ProducerLN", _
"ClientFN", "ClientMI", "ClientLN")
'Finds the producer cell location
Set rFndP1 = Sheet2.Cells.Find( _
What:="Producer:", LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
'Finds the next producer cell location
Set rFndP2 = Sheet2.Cells.FindNext(rFndP1)
'Ends the Sub
If rFndP1 Is Nothing Then Exit Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Because the report is extracted from a .PDF file it does not list the client with any type
'of identifier. Although, if you look in column B you will find the text "LTC" in the same row
'as the client's name. This Find method searches for "LTC" and then I offset this cell location
'to pull the client's name.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set rFndC = Sheet2.Range(rFndP1, rFndP2).Find( _
What:="LTC", LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
' save the address of the first found cell
sAdr = rFndP1.Address
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'THIS DO WHILE LOOP parses out the producers and the clients names into three cells which will
'later be use with data validation to add the producer's name to a client list
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'PROBLEM1: The producers and clients do not always follow the same name pattern. Generally the producer
'will follow "Producer: First MiddleInitial Last" pattern and the client "First MiddleInitial Last"
'pattern but there are case cases where both the producer and the client do not have Middle Initials.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'PROBLEM2: I need to list the producer once for each occurrence of their clients. This relationship
'between the producer and client is one to many and in the report it will list the producer and
'then the clients below.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Do
astr1 = Split(WorksheetFunction.Trim(rFndP1.Value), " ")
astr2 = Split(WorksheetFunction.Trim(rFndC.Offset(0, -1).Value), " ")
Set rOut = Sheet1.Cells(Rows.Count, "A").End(xlUp).Offset(1)
rOut(1, "A").Value = astr1(1)
rOut(1, "B").Value = astr1(2)
rOut(1, "C").Value = astr1(3)
rOut(1, "D").Value = astr2(1)
rOut(1, "E").Value = astr2(2)
rOut(1, "F").Value = astr2(3)
Set rFndP1 = Sheet2.Cells.FindNext(rFndP1)
Loop While rFndP1.Address <> sAdr
End Sub