Multiple If(Match not working as I'd expect

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.



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]
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Edit: First three codes are length of 2 (no spaces before or after)

Code:
[TABLE="width: 216"]
<tbody>[TR]
[TD]Exclusion Codes[/TD]
[TD]Code Notes[/TD]
[/TR]
[TR]
[TD]AP[/TD]
[TD]Length = 2[/TD]
[/TR]
[TR]
[TD]DD[/TD]
[TD]Length = 2[/TD]
[/TR]
[TR]
[TD]RO[/TD]
[TD]Length = 2[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Nevermind. This is just another case, as seen in other posts throughout the information superhighway, where ISNUMBER( needs to be added before MATCH(.
 
Upvote 0

Forum statistics

Threads
1,214,537
Messages
6,120,096
Members
448,944
Latest member
SarahSomethingExcel100

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