Is there a way I can simplify this formula?
=IFERROR(IF(LEN(RIGHT(K3,LEN(K3)-FIND("@",SUBSTITUTE(K3," ","@",LEN(K3)-LEN(SUBSTITUTE(K3," ",""))))))<4,IF(LEN(RIGHT(K3,LEN(K3)-FIND("@",SUBSTITUTE(K3," ","@",LEN(K3)-LEN(SUBSTITUTE(K3," ",""))))))< 3,IF(LEN("00"&LEFT(RIGHT(K3,2),1)+1&"l")>4,"0"&LEFT(RIGHT(K3,2),1)+1&"l","00"&LEFT(RIGHT(K3,2),1)+1&"l"),IF(LEN("0"&LEFT(RIGHT(K3,3),2)+1&"l")<4,"00"&LEFT(RIGHT(K3,3),2)+1&"l","0"&LEFT(RIGHT(K3,3),2)+1&"l")),IF(LEN(LEFT(RIGHT(K3,4),3)+1&"l")<4,IF(LEN(LEFT(RIGHT(K3,4),3)+1&"l")< 3,"00"&LEFT(RIGHT(K3,4),3)+1&"l","0"&LEFT(RIGHT(K3,4),3)+1&"l"),(LEFT(RIGHT(K3,4),3)+1&"l"))),IF(LEN(K3)<4,IF(LEN(K3)< 3,IF(LEN("00"&LEFT(K3,1)+1&"l")>4,"0"&LEFT(K3,1)+1&"l","00"&LEFT(K3,1)+1&"l"),IF(LEN("0"&LEFT(K3,2)+1&"l")<4,"00"&LEFT(K3,2)+1&"l","0"&LEFT(K3,2)+1&"l")),IF(LEN(LEFT(K3,3)+1&"l")< 3,"00" & LEFT(K3,3)+1&"l", IF(LEN(LEFT(K3,3)+1&"l")<4,"0"&LEFT(K3,3)+1&"l",LEFT(K3,3)+1&"l"))))
It had to find the last number in the cell, add 1 to it and put an a L at the end. If the number was under 3 digits then 0's would have to be added before the number (083, 071, 043, 005, 002 etc).
Input - Output
1L - 002L
03R - 004L
483L - 484L
232R 233L 234L - 235L
08L 009L - 010L
4L 005R 6R - 007L
89L 90R 91L - 092L
This often happens when copying and pasting or exporting large amounts of data from the web into Excel. You need to simplify your data—just not manually. Seeing as Excel offers hundreds of different features and formulas, you’re faced with another dilemma: how do you start simplifying?
Even after you develop your own formulas, you may have trouble understanding them weeks or months later. One way to make formulas a bit easier to understand is to use Alt+Enter in the middle of the formula to "format" how it appears on the screen. Consider, for instance, the following long formula:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3043) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Dealing with Long Formulas.
Excel’s new LET function provides essentially the same functionality, with one notable difference. With LET, you can only use the variable you declare in the same formula that contains the LET function. As a simplified first example of working with LET, consider the following formula in Excel.
This works for your examples:
=TEXT(-LOOKUP(2,-MID(TRIM(RIGHT(SUBSTITUTE(K3," ",REPT(" ",1000)),1000)),1,ROW($1:$15)))+1,"000L")
Another one using FILTERXML:
=TEXT(FILTERXML("<t><s>"&SUBSTITUTE(LEFT(K3,LEN(K3)-1)," ","</s><s>")&"</s></t>","//s[last()]")+1,"000")&"L"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With