5280_BIDev
New Member
- Joined
- Apr 7, 2014
- Messages
- 3
An Excel spreadsheet currently exists which has several years worth of data. In the past, exclusion codes were eight characters in length and they were always at the end of the comment. The previous formula worked fine before the exclusion codes were changed and the method of entering the comments had changed.
I've been trying to figure out how to script a new formula to get my Wanted Result below. I've extended the Exclusion Codes from just 'AP', 'DD', and 'RO' to include variations that could be found in the comments. Old codes will still be a part of the formula, but for the sake of this post we'll consider those irrelevant for now.
Using individual instances of if(match (see 1, 2, 3), I can get various results, but if I nest those individual formulas into one formula, then I don't get the result that I am expecting. Can someone straighten me out? I've been beating my heading against the wall trying to figure this out for far too many hours now.
I've been trying to figure out how to script a new formula to get my Wanted Result below. I've extended the Exclusion Codes from just 'AP', 'DD', and 'RO' to include variations that could be found in the comments. Old codes will still be a part of the formula, but for the sake of this post we'll consider those irrelevant for now.
Using individual instances of if(match (see 1, 2, 3), I can get various results, but if I nest those individual formulas into one formula, then I don't get the result that I am expecting. Can someone straighten me out? I've been beating my heading against the wall trying to figure this out for far too many hours now.
Code:
[TABLE="width: 906"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Wanted[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Exclusion Codes[/TD]
[TD]Code Notes[/TD]
[TD][/TD]
[TD]Comments[/TD]
[TD]Result[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AP[/TD]
[TD]Len(h13) = 2[/TD]
[TD][/TD]
[TD]The dog is wearing pajamas - DD[/TD]
[TD]DD[/TD]
[TD]DD[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]DD[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]DD[/TD]
[TD]Len(h14) = 3[/TD]
[TD][/TD]
[TD]AP[/TD]
[TD]AP[/TD]
[TD]AP[/TD]
[TD]AP[/TD]
[TD]AP[/TD]
[TD]AP[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]RO[/TD]
[TD]Len(h15) = 4[/TD]
[TD][/TD]
[TD]No codes here[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]#N/A[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AP-[/TD]
[TD]hyphen after code[/TD]
[TD][/TD]
[TD]RO 134357[/TD]
[TD]RO[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]RO[/TD]
[TD]#N/A[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]DD-[/TD]
[TD]hyphen after code[/TD]
[TD][/TD]
[TD]795846[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]#N/A[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]RO-[/TD]
[TD]hyphen after code[/TD]
[TD][/TD]
[TD]DD[/TD]
[TD]DD[/TD]
[TD]DD[/TD]
[TD]DD[/TD]
[TD]DD[/TD]
[TD]DD[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]AP[/TD]
[TD]space after code[/TD]
[TD][/TD]
[TD]Sun and stars -AP[/TD]
[TD]AP[/TD]
[TD]AP[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]AP[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]DD[/TD]
[TD]space after code[/TD]
[TD][/TD]
[TD]Road[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]#N/A[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]RO[/TD]
[TD]space after code[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]-AP[/TD]
[TD]hyphen before code[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]-DD[/TD]
[TD]hyphen before code[/TD]
[TD][/TD]
[TD]Equivalent SQL Server[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]-RR[/TD]
[TD]hyphen before code[/TD]
[TD][/TD]
[TD="colspan: 7"]WHEN RIGHT(poh.comments, 3) IN ('-DD','-AP','-RO',' DD',' AP',' RO') THEN RIGHT(poh.comments, 2)[/TD]
[/TR]
[TR]
[TD] AP[/TD]
[TD]space before code[/TD]
[TD][/TD]
[TD="colspan: 7"]WHEN LEFT(poh.comments, 3) IN ('DD-','AP-','RO-','DD ','AP ','RO ') THEN LEFT(poh.comments, 2)[/TD]
[/TR]
[TR]
[TD] DD[/TD]
[TD]space before code[/TD]
[TD][/TD]
[TD="colspan: 4"]WHEN poh.comments IN ('AP','DD','RO') THEN poh.comments[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD] RR[/TD]
[TD]space before code[/TD]
[TD][/TD]
[TD]ELSE '0'[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]1) IF(ISERROR(MATCH(RIGHT(K13,3),$H$13:$H$27,0)),0,IF(MATCH(RIGHT(K13,3),$H$13:$H$27,0),RIGHT(K13,2),0))[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]2) IF(ISERROR(MATCH(K13,$H$13:$H$27,0)),0,IF(MATCH(K13,$H$13:$H$27,0),K13,0))[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 7"]3) IF(ISERROR(MATCH(LEFT(K13,3),$H$13:$H$27,0)),0,IF(MATCH(LEFT(K13,3),$H$13:$H$27,0),LEFT(K13,2),0))[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 10"]4) IF(MATCH(RIGHT(K13,3),$H$13:$H$27,0),RIGHT(K13,2), IF(MATCH(K13,$H$13:$H$27,0),K13, IF(MATCH(LEFT(K13,3),$H$13:$H$27,0),LEFT(K13,2),0)))[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]