Forumla/ LookUp to find preceding ID

AFGPB

New Member
Joined
Mar 16, 2016
Messages
5
Hello everybody :),

I got a little excel task to do, however I really cannot get my head around how to solve it, so I hope you guys can help me out.

The problem:
I have a list of contracts with contract IDs in column A. However, not all of the contracts are completely different ones. Some of them just got replaced or extended by a "new" contract, in which case the ID gets additional digits or letters, however the original serial number is always the same.

My goal:
I have been asked to find out for each contracts if there is a preceding one. Meaning if a contract has been replaced or extended by a new one then I want to have the number of the preceding contract in columns C.
There can also be the case a contract has 2 additional extensions, there has been added even more digits/ letters, but I also want to see the preceding one.

I hope I explained myself correctly.
here is also a small sample which hopefully helps to understand the concept. https://ibb.co/jaNfJG


jaNfJG

I am looking forward to your answers and thanks a lot already.
If you have any questions, please let me know.

Thank you!
AF
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
see if this works for you


Excel 2013/2016
AB
1IDPreceding
2AG0002/TS2-KK 
3AG0002/620AGAY
4AG018-1
5AG019-6
6AG019-7AG019-6
7AG022-4
8AG022-4A01AG022-4
9AG022-4A02AG022-4A01
10AG022-4A03AG022-4A02
11AG023-1
Sheet2
Cell Formulas
RangeFormula
B2=IF(ISERROR(MATCH(TRIM(LEFT(SUBSTITUTE(A2,"-",REPT(" ",500)),500))&"*",$A1:A$1,0)),"",A1)
 
Upvote 0
Hello AlanY,


Incredible, this works really wonderful. Thank you so much!!!
Unfortunately they added one more complication to the task.


Some of the contracts are called XXXXX-XE
Those contracts are separate contracts and do not relate to the one with XXXXX even though they have the same main serial number.
Other contracts, however like XXXXX-XA and XXXXX-XR do relate, so for those the formula works perfectly.
My questions is if it is possible to handle this exceptions.




[TABLE="width: 611"]
<tbody>[TR]
[TD="colspan: 2"]NOW[/TD]
[TD="colspan: 2"]HOW IT SHOULD BE[/TD]
[/TR]
[TR]
[TD]AG023-1[/TD]
[TD][/TD]
[TD]AG023-1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG023-9[/TD]
[TD]AG023-1[/TD]
[TD]AG023-9[/TD]
[TD]AG023-1[/TD]
[/TR]
[TR]
[TD]AG023-9E01[/TD]
[TD]AG023-9[/TD]
[TD]AG023-9E01[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG023-9R01[/TD]
[TD]AG023-9E01[/TD]
[TD]AG023-9R01[/TD]
[TD]AG023-9[/TD]
[/TR]
[TR]
[TD]AG024-1[/TD]
[TD][/TD]
[TD]AG024-1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG025-1[/TD]
[TD][/TD]
[TD]AG025-1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG025-2[/TD]
[TD]AG025-1[/TD]
[TD]AG025-2[/TD]
[TD]AG025-1[/TD]
[/TR]
[TR]
[TD]AG026-1[/TD]
[TD][/TD]
[TD]AG026-1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG027-1[/TD]
[TD][/TD]
[TD]AG027-1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG027-1E01[/TD]
[TD]AG027-1[/TD]
[TD]AG027-1E01[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG028-1[/TD]
[TD][/TD]
[TD]AG028-1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG028-1R01[/TD]
[TD]AG028-1[/TD]
[TD]AG028-1R01[/TD]
[TD]AG028-1[/TD]
[/TR]
[TR]
[TD]AG029-3[/TD]
[TD][/TD]
[TD]AG029-3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG029-3A01[/TD]
[TD]AG029-3[/TD]
[TD]AG029-3A01[/TD]
[TD]AG029-3[/TD]
[/TR]
[TR]
[TD]AG030-1[/TD]
[TD][/TD]
[TD]AG030-1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG030-1A01[/TD]
[TD]AG030-1[/TD]
[TD]AG030-1A01[/TD]
[TD]AG030-1[/TD]
[/TR]
[TR]
[TD]AG031-3[/TD]
[TD][/TD]
[TD]AG031-3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG031-3A01[/TD]
[TD]AG031-3[/TD]
[TD]AG031-3A01[/TD]
[TD]AG031-3[/TD]
[/TR]
[TR]
[TD]AG031-3E01[/TD]
[TD]AG031-3A01[/TD]
[TD]AG031-3E01[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG031-3E01A01[/TD]
[TD]AG031-3E01[/TD]
[TD]AG031-3E01A01[/TD]
[TD]AG031-3E01[/TD]
[/TR]
[TR]
[TD]AG032-1[/TD]
[TD][/TD]
[TD]AG032-1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG032-1E01[/TD]
[TD]AG032-1[/TD]
[TD]AG032-1E01[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG032-1E01R01[/TD]
[TD]AG032-1E01[/TD]
[TD]AG032-1E01R01[/TD]
[TD]AG032-1E01[/TD]
[/TR]
[TR]
[TD]AG032-1E01R02[/TD]
[TD]AG032-1E01R01[/TD]
[TD]AG032-1E01R02[/TD]
[TD]AG032-1E01R01[/TD]
[/TR]
[TR]
[TD]AG033-1[/TD]
[TD][/TD]
[TD]AG033-1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG033-1E01[/TD]
[TD]AG033-1[/TD]
[TD]AG033-1E01[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG034-1[/TD]
[TD][/TD]
[TD]AG034-1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG034-1E01[/TD]
[TD]AG034-1[/TD]
[TD]AG034-1E01[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AG034-1R01[/TD]
[TD]AG034-1E01[/TD]
[TD]AG034-1R01[/TD]
[TD]AG034-1[/TD]
[/TR]
</tbody>[/TABLE]



https://ibb.co/b2VYOG


Thank you so much for your help. It's incredible how fast you guys answer.

Cheers!
 
Upvote 0
not the most elegant solution by far, but works for your sample data


Excel 2013/2016
AB
1IDPreceding
2AG023-1 
3AG023-9AG023-1
4AG023-9E01
5AG023-9R01AG023-9
6AG024-1
7AG025-1
8AG025-2AG025-1
9AG026-1
10AG027-1
11AG027-1E01
12AG028-1
13AG028-1R01AG028-1
14AG029-3
15AG029-3A01AG029-3
16AG030-1
17AG030-1A01AG030-1
18AG031-3
19AG031-3A01AG031-3
20AG031-3E01
21AG031-3E01A01AG031-3E01
22AG032-1
23AG032-1E01
24AG032-1E01R01AG032-1E01
25AG032-1E01R02AG032-1E01R01
26AG033-1
27AG033-1E01
28AG034-1
29AG034-1E01
30AG034-1R01AG034-1
Sheet1
Cell Formulas
RangeFormula
B2=IF(AND(MID(A2,8,1)="E",MID(A1,8,1)<>"E"),"",IF(ISERROR(MATCH(TRIM(LEFT(SUBSTITUTE(A2,"-",REPT(" ",500)),500))&"*",$A$1:A1,0)),"",IF(AND(MID(A1,8,1)="E",MID(A2,8,1)<>"E"),INDEX(A:A,MATCH(LEFT(A2,7),A:A,0)),A1)))
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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