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]
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

5280_BIDev

New Member
Joined
Apr 7, 2014
Messages
3
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]
 

5280_BIDev

New Member
Joined
Apr 7, 2014
Messages
3
Nevermind. This is just another case, as seen in other posts throughout the information superhighway, where ISNUMBER( needs to be added before MATCH(.
 

Watch MrExcel Video

Forum statistics

Threads
1,101,805
Messages
5,482,994
Members
407,371
Latest member
Ernest F Mink

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top