Forum Discussion
orglenda1740
Feb 16, 2024Copper Contributor
Using IF functions to merge multiple formulas
I have two scenarios that I need help with.
1. Removing an alpha character from a string that can be at the beginning or the end. Column B value in this case is R24615 or could be (for example) 10873R or 4623R. I only need the numeric characters as result.
REPLACE Combo | R24615 | =IF(OR(LEFT($b37,1)="R",REPLACE($b37,1,1,""),(RIGHT($b37,1)="R",REPLACE($b37,6,1,""),(RIGHT($b37,1)="R",REPLACE($b37,5,1,""))) | FALSE |
2. Line 1 below the answer I am looking for is 132. Line 2 the answer I am looking for is 181. I tried IFERROR which works individually for both, but I do not know how to combine the formulas to work together.
13201611.62401.001 | =IFERROR($F10*(LEFT(E10,3))="986",(RIGHT(E10,3)))*LEFT(E10,3) | 132 |
98601000.25992.181 | =IFERROR($F11*(LEFT(F11,3))="986",(RIGHT(F11,3))) | 181 |
- peiyezhuBronze Contributor
- JamesMartin001Copper Contributor
orglenda1740 You can use the Formula SUBSTITUTE to replace instances of a character or a particular text string within a longer string.
I am using this sometimes up to 11 times so far when creating unique references between databases in different formats (same data but recorded by different departments). You wrap the SUBSTITUTE formula around the previous one, for additional text correction. I think there is no limit to number of times you can use. TRIM formula is useful to get rid of extra spaces at the end of a cell total string, and if double spaced within the string.
Regarding identifying Regular Expressions I am using a macro added to a macro enabled workbook. This works well and you should find examples online, I am using one from ExcelDemy, but I seem to be unable to get the macro to work in multiple xlsm files. You can wrap other Excel formulas around the RegEx.
I use SUBSTITUTE with TEXTBEFORE and TEXTAFTER, the latter two are interesting, as they can be nested via the last optional value in the formula if a word is not found. This was critical for me when extracting a unique reference from address data in my case recreating the High Rise Block names, that end with 3 unique words. When trapping the word before these 3 words via a nested TEXTBEFORE, in a 2nd helper column you use TEXTAFTER to trap the last word, and then add them together via contacting with & in a third column.
- orglenda1740Copper ContributorThank you, James. I think this will come in handy as I get more involved in more complex analyses.
- Rodrigo_Steel Contributor
orglenda1740
1. Revised formula=IF(ISNUMBER(LEFT(B1,1)*1), LEFT(B1, LEN(B1)-1), RIGHT(B1, LEN(B1)-1))
2. Combined formula:
=IFERROR(IF(LEFT($F10,3)="986", RIGHT($F10,3), RIGHT($F10,3)*LEFT($F10,3)), "")
- orglenda1740Copper Contributor
Rodrigo_ Thank you for your help.