Trust me, I am pulling my hair out. I have never see such a mess come out of a database before. It is a third party vendor and I have already complained about this. From what I know, other clients have complained as well. With that said, my goal has always been to pull the alleged value from the corresponding cell.
I managed to solve it on my own........here is the logic:
Column AN: 1. Alleged2. 3rd Party Witness3. Alleged4. Alleged5. Complainant
Column AP: 1. Non-Management2. Supervisor3. Non-Management4.
Helper Column E: =LEN(A2)-LEN(SUBSTITUTE(UPPER(A2),".","")) This counts the periods in the first column cell value. I used this to count the number of values in the cell. The one thing about this data set output is that if there is a number, it is always followed by a period.
Helper Column F: =IF(ISERROR(FIND("Alleged",$AN2,1)),"",FIND("Alleged",$AN2,1)) This gets me the position of the first alleged = 4
Helper Column G: =IF(ISERROR(FIND("Alleged",$AN2,F2+1)),"",FIND("Alleged",$AN2,F2+1)) This gets me the position of the second alleged = 34
Helper Column H: =IF(ISERROR(FIND("Alleged",$AN2,G2+1)),"",FIND("Alleged",$AN2,G2+1)) This gets me the position of the third alleged
Helper Column I: =IF(ISERROR(FIND("Alleged",$AN2,H2+1)),"",FIND("Alleged",$AN2,H2+1)) This gets me the position of the fourth alleged
Helper Column J: =IF(ISERROR(FIND("Alleged",$AN2,I2+1)),"",FIND("Alleged",$AN2,I2+1)) This gets me the position of the fifth alleged
** I stopped at 5 columns because I did not ever see more than 5 alleged.
Helper Column K: =IF(ISERROR(IF(F2="","",MID($AN2,FIND("Alleged",$AN2,F2)-3,1))),"",IF(F2="","",MID($AN2,FIND("Alleged",$AN2,F2)-3,1))) Returns the number 1 for the first alleged
Helper Column L: =IF(ISERROR(IF(G2="","",MID($AN2,FIND("Alleged",$AN2,G2)-3,1))),"",IF(G2="","",MID($AN2,FIND("Alleged",$AN2,G2)-3,1))) Returns the number 3 for the second alleged
Helper Column M: =IF(ISERROR(IF(H2="","",MID($AN2,FIND("Alleged",$AN2,H2)-3,1))),"",IF(H2="","",MID($AN2,FIND("Alleged",$AN2,H2)-3,1))) Returns third number if there is one
Helper Column N: =IF(ISERROR(IF(I2="","",MID($AN2,FIND("Alleged",$AN2,I2)-3,1))),"",IF(I2="","",MID($AN2,FIND("Alleged",$AN2,I2)-3,1))) Returns fourth number if there is one
Helper Column O: =IF(ISERROR(IF(J2="","",MID($AN2,FIND("Alleged",$AN2,J2)-3,1))),"",IF(J2="","",MID($AN2,FIND("Alleged",$AN2,J2)-3,1))) Returns fifth number if there is one
Output Column P: This works for all contingencies for finding the corresponding value for alleged in another cell.
=IF(A2="",IF(K2="","",IF(AND(E2+0>K2+0,K2<>"",L2=""),MID(AP2,FIND(K2,AP2,1)+3,FIND(K2+1,AP2,1)-FIND(K2,AP2,1)-3),IF(AND(E2+0=K2+0,K2<>"",L2=""),TRIM(RIGHT(AP2,LEN(AP2)-FIND(K2,AP2)-2)),IF(K2="1",MID(AP2,FIND(K2,AP2,1)+3,FIND("2",AP2,1)-FIND(K2,AP2,1)-3),IF(K2="2",MID(AP2,FIND(K2,AP2,1)+3,FIND(L2,AP2,1)-FIND(K2,AP2,1)-3))))))
Output Column Q: This pulls the value of the second alleged.
=IF(L2="","",IF(AND($E2+0>L2+0,L2<>"",M2=""),MID($AP2,FIND(L2,$AP2,1)+3,FIND(L2+1,$AP2,1)-FIND(L2,$AP2,1)-3),IF(AND($E2+0=L2+0,L2<>"",M2=""),TRIM(RIGHT($AP2,LEN($AP2)-FIND(L2,$AP2)-2)),IF(AND($E2+0>L2+0,L2<>"",M2<>""),MID($AP2,FIND(L2,$AP2,1)+3,FIND(L2+1,$AP2,1)-FIND(L2,$AP2,1)-3)))))
I won't go on but I think I have provided enough examples of how to solve for this if anyone is reading. I have other values to pull for each alleged in other columns so I can re-use columns K thru O again to pull the values.