Smarter way for this IF Formula to work

FredFlamingo

New Member
Joined
Apr 24, 2020
Messages
8
Platform
  1. Windows
Hi all,

I have a rather disgusting looking IF formula in work, i have pasted it below but do not expect people to read it, but i am wondering, is there some smarter way to do what i want it to do, basically one cell put in a short code E.g. E2004 and it spits out a set sentence, sometimes additional info can be added at the end of it and this is what column AC is for. if anyone has any ideas how to tame this beast, please offer some suggestions.

=IF(AD2<>"",(AD2),IF(F2="E2004",(CONCATENATE(AB2,AY2," ",H2," ","Househunting ","(",TEXT(I2,"m/d/yy"),")"," Airfare ",AC2)),IF(F2="E2007",(CONCATENATE(AB2,AY2," ",H2," ","Settling In Service ",X2,Z2)),IF(F2="E2002",(CONCATENATE(AB2,AY2," ",H2," ","Househunting ","(",TEXT(I2,"m/d/yy"),")"," Lodging ","(",L2,")")),IF(F2="E2008",(CONCATENATE(AB2,AY2," ",H2," ","Area Tour ",X2)),IF(F2="E2010",(CONCATENATE(AB2,AY2," ",H2," ","Home Finding ",X2)),IF(F2="E2011",(CONCATENATE(AB2,AY2," ",H2," ","Settling In ",Z2)),IF(F2="E2020",(CONCATENATE(AB2,AY2," ",H2," ","Departure Services ",AC2)),IF(F2="E2021",(CONCATENATE(AB2,AY2," ",H2," ","Departure Services Vendor Fee",AC2)),IF(F2="E2123",(CONCATENATE(AB2,AY2," ",H2," ","Home Sale Title Coordination Fees",AC2)),IF(F2="E2124",(CONCATENATE(AB2,AY2," ",H2," ","Home Sale ","(",TEXT(I2,"m/d/yy"),")"," Inspection ","(",AA2,")")),IF(F2="E2125",(CONCATENATE(AB2,AY2," ",H2," ","Home Sale Appraisal ",AC2)),IF(F2="E2133",(CONCATENATE(AB2,AY2," ",H2," ","Inventory - HOA Dues ",AC2)),IF(F2="E2134",(CONCATENATE(AB2,AY2," ",H2," ","Inventory - Maintenance ",AC2)),IF(F2="E2135",(CONCATENATE(AB2,AY2," ",H2," ","Inventory - Mortgage Payment ",AC2)),IF(F2="E2136",(CONCATENATE(AB2,AY2," ",H2," ","Inventory - Utilities ",AC2)),IF(F2="E2102",(CONCATENATE(AB2,AY2," ",H2," ","Home Purchase Closing Costs ",AC2)), IF(F2="E2140",(CONCATENATE(AB2,AY2," ",H2," ","Temp Living ","(",TEXT(I2,"m/d/yy"),")"," Lodging ","(",L2,") Origin")),IF(F2="E2145",(CONCATENATE(AB2,AY2," ",H2," ","Temp Living ","(",TEXT(I2,"m/d/yy"),")"," Lodging ","(",L2,")")),IF(F2="E2146",(CONCATENATE(AB2,AY2," ",H2," ","Temp Living ","(",TEXT(I2,"m/d/yy"),")"," Car Rental ","(",L2,")")),IF(F2="E2148",(CONCATENATE(AB2,AY2," ",H2," ","Temp Living ","(",TEXT(I2,"m/d/yy"),") ",AC2)),IF(F2="E2151",(CONCATENATE(AB2,AY2," ",H2," ","Temp Living Vendor Fee ",AC2)),IF(F2="E2155",(CONCATENATE(AB2,AY2," ",H2," ","Temp Living ","(",TEXT(I2,"m/d/yy"),") ","Airport Taxi")),IF(F2="E2157",(CONCATENATE(AB2,AY2," ",H2," ","Temp Living ","(",TEXT(I2,"m/d/yy"),")"," Parking ","(",L2,")")),IF(F2="E2158",(CONCATENATE(AB2,AY2," ",H2," ","Temp Living ","(",TEXT(I2,"m/d/yy"),")"," Furniture Rental ","(",L2,")")),IF(F2="E2161",(CONCATENATE(AB2,AY2," ",H2," ","Business Final Move ","(",TEXT(I2,"m/d/yy"),")"," Airfare ",AC2)),IF(F2="E2162",(CONCATENATE(AB2,AY2," ",H2," ","Bus Temp Living ","(",TEXT(I2,"m/d/yy"),")"," Lodging ","(",L2,")")),IF(F2="E2166",(CONCATENATE(AB2,AY2," ",H2," ","Bus Temp Living ","(",TEXT(I2,"m/d/yy"),")"," Car Rental ","(",L2,")")), IF(F2="E2167",(CONCATENATE(AB2,AY2," ",H2," ","Bus Temp Living Vendor Fee ",AC2)),IF(F2="E2180",(CONCATENATE(AB2,AY2," ",H2," ","Business Final Move ","(",TEXT(I2,"m/d/yy"),")"," Airfare ",AC2)),IF(F2="E2190",(CONCATENATE(AB2,AY2," ",H2," ","Candidate Trip ","(",TEXT(I2,"m/d/yy"),")"," Airfare ",AC2)),IF(F2="E2200",(CONCATENATE(AB2,AY2," ",H2," ","Home Leave ","(",TEXT(I2,"m/d/yy"),")"," Airfare ",AC2)),IF(F2="E2201",(CONCATENATE(AB2,AY2," ",H2," ","Home Leave ","(",TEXT(I2,"m/d/yy"),")"," Airfare ",AC2)),IF(F2="E2223",(CONCATENATE(AB2,AY2," ",H2," ","Property Management Services ","(",TEXT(I2, "mmmm") & " " & TEXT(I2, "yyyy"),")",)), IF(F2="E2226",(CONCATENATE(AB2,AY2," ",H2," ","Property Management Services ","(",TEXT(I2, "mmmm") & " " & TEXT(I2, "yyyy"),") VAT",)),IF(F2="E2240",(CONCATENATE(AB2,AY2," ",H2," ","Host Housing Vendor Fee ",AC2)),IF(F2="E2241",(CONCATENATE(AB2,AY2," ",H2," ","Real Estate Agency Fee ")),IF(F2="E2244",(CONCATENATE(AB2,AY2," ",H2," ","Host Housing Security Deposit ")), IF(F2="E2246",(CONCATENATE(AB2,AY2," ",H2," ","Host Housing ","(",TEXT(I2, "mmmm") & " " & TEXT(I2, "yyyy"),") ",AC2)),IF(F2="E2247",(CONCATENATE(AB2,AY2," ",H2," ","Host Housing ","(",TEXT(I2,"m/d/yy"),")"," Furniture Rental ",)),IF(F2="E2260",(CONCATENATE(AB2,AY2," ",H2," ","Cross Cultural Training",Y2)),IF(F2="E2261",(CONCATENATE(AB2,AY2," ",H2," ","Language Training ",Y2,AC2)),IF(F2="E2262",(CONCATENATE(AB2,AY2," ",H2," ","Cross Cultural Training",Y2," ",AC2)),IF(F2="E2263",(CONCATENATE(AB2,AY2," ",H2," ","Language Training ",Y2," ",AC2)),IF(F2="E2264",(CONCATENATE(AB2,AY2," ",H2," ","Spousal Assistance ",Y2)),IF(F2="E2266",(CONCATENATE(AB2,AY2," ",H2," ","Mercer Fees ")), IF(F2="E2270",(CONCATENATE(AB2,AY2," ",H2," ","Immigration Assistance - ",AC2)),IF(F2="E2271",(CONCATENATE(AB2,AY2," ",H2," ","Immigration Assistance ",AC2)), IF(F2="E2272",(CONCATENATE(AB2,AY2," ",H2," ","Immigration Assistance - ",AC2)),IF(F2="E2273",(CONCATENATE(AB2,AY2," ",H2," ","Immigration Assistance - ",AC2)), IF(F2="E2274",(CONCATENATE(AB2,AY2," ",H2," ","Immigration Assistance - ",AC2)),IF(F2="E2275",(CONCATENATE(AB2,AY2," ",H2," ","Immigration Assistance ",AC2)), IF(F2="E2276",(CONCATENATE(AB2,AY2," ",H2," ","Immigration Assistance - ",AC2)), IF(F2="E2277",(CONCATENATE(AB2,AY2," ",H2," ","Immigration Assistance - ",AC2)),IF(F2="E2282",(CONCATENATE(AB2,AY2," ",H2," ","Host Auto Lease ","(",TEXT(I2,"m/d/yy"),") ",AC2)),IF(F2="E2290",(CONCATENATE(AB2,AY2," ",H2," ","School Tutition Deposit ",AC2)),IF(F2="E2291",(CONCATENATE(AB2,AY2," ",H2," ","School Tutition ",AC2)),IF(F2="E2292",(CONCATENATE(AB2,AY2," ",H2," ","School Transportation ",AC2)),IF(F2="E2350",(CONCATENATE(AB2,AY2," ",H2," ","Discard/Donate")), IF(F2="E2351",(CONCATENATE(AB2,AY2," ",H2," ","Household Goods Auto - ",AC2)), IF(F2="E2352",(CONCATENATE(AB2,AY2," ",H2," ","Household Goods Pet Shipment ",AC2)),IF(F2="E2355",(CONCATENATE(AB2,AY2," ",H2," ","Household Goods ","(",I2,,") ","Perm Storage",AC2)),IF(F2="E2356",(CONCATENATE(AB2,AY2," ",H2," ","Household Goods Vat ",AC2)),IF(F2="E2370",(CONCATENATE(AB2,AY2," ",H2," ","Final Move ","(",TEXT(I2,"m/d/yy"),")"," Airfare ",AC2)),IF(F2="E2374",(CONCATENATE(AB2,AY2," ",H2," ","Final Move ","(",TEXT(I2,"m/d/yy"),")"," Lodging ","(",L2,")")),IF(F2="E2421",(CONCATENATE(AB2,AY2," ",H2," ","Tax Consultation ",AC2)),IF(F2="E2438",(CONCATENATE(AB2,AY2," ",H2," ","Health Insurance Payment Allowance ","(",TEXT(I2, "mmmm") & " " & TEXT(I2, "yyyy"),")",)),IF(F2="E2501",(CONCATENATE(AB2,AY2," ",H2," ","Rental Assistance ",X2)),IF(F2="E2283",(CONCATENATE(AB2,AY2," ",H2," ","Host Auto Lease VAT ","(",TEXT(I2,"m/d/yy"),") ",AC2)),(""))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
There are a few things you may be able to do, i.e.:

1. Create a lookup table, that has the value you want to look-up (i.e. "E2004") and have columns of data related to that that you might want to return.
Then you can use functions like VLOOKUP or INDEX/MATCH to return the related information you want.
See this is you are not familiar with VLOOKUP: How to use the Excel VLOOKUP function | Exceljet

2. Create your own User Defined Function (UDF) in VBA that does what you want. The advantage to doing it this way is it is a little easier to read and manage (as it will appear in a structured, more readable format). And if you ever have to make changes to it, you only need to update the one User Defined Function in VBA, and not every instance of the formula on your worksheet. There are lots of articles and tutorials on creating UDFs that you can find with a simple Google search.
 
Upvote 0
@FredFlamingo I totally agree with what @Joe4 has posted.

However, curiosity got me looking at this.
The below approach is, arguably, a bit less 'disgusting' than your original.
Your formula is a bit boggling but I think the Substitutions in my formula are enough to cope with creating all of your sentences.
Hopefully, the examples in the Sentance Lookup table indicate how they are constructed. Basic text and including strings bounded by single quotes that represent the data that you wish to have substituted. Hope that makes sense?

MRXLMAY21.xlsm
ABFGHIJKLWXYZAAABACADAY
1
2AB-Stuff2 AY-Stuff Stuff in H2 Househunting (22/06/01) Airfare OtherE2002Stuff in H222/06/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff2OtherAY-Stuff
3AB-Stuff3 AY-Stuff Stuff in H3 Househunting (23/06/01) Lodging L-StuffE2004Stuff in H323/06/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff3OtherAY-Stuff
4AB-Stuff4 AY-Stuff Stuff in H4 Settling In Service X-Stuff Z-Stuff E2007Stuff in H424/06/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff4OtherAY-Stuff
5AB-Stuff5 AY-Stuff Stuff in H5 Area Tour X-Stuff E2008Stuff in H525/06/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff5OtherAY-Stuff
6AB-Stuff6 AY-Stuff Stuff in H6 Homefinding X-Stuff E2010Stuff in H626/06/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff6OtherAY-Stuff
7AB-Stuff7 AY-Stuff Stuff in H7 Departure Services OtherE2020Stuff in H727/06/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff7OtherAY-Stuff
8AB-Stuff8 AY-Stuff Stuff in H8 Departure Services Vendor Fee OtherE2021Stuff in H828/06/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff8OtherAY-Stuff
9AB-Stuff9 AY-Stuff Stuff in H9 Home Sale Title Coordination Fees OtherE2123Stuff in H929/06/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff9OtherAY-Stuff
10AB-Stuff10 AY-Stuff Stuff in H10 Home Sale (30/06/01) Inspection (AAAAA )E2124Stuff in H1030/06/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff10OtherAY-Stuff
11AB-Stuff11 AY-Stuff Stuff in H11 Health Insurance Payment Allowance (July 2001)E2438Stuff in H1101/07/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff11OtherAY-Stuff
12AD StuffE2002Stuff in H1202/07/2001L-StuffX-StuffZ-StuffAAAAAAB-Stuff12OtherAD Stuff
WS1
Cell Formulas
RangeFormula
A2:A12A2=IF(AD2<>"",(AD2),AB2&" "&AY2&" "&H2&" "&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOOKUP(F2,Sheet4!$A$2:$B$11),"'I'",TEXT(I2,"dd/mm/yy")),"'AC'",AC2),"'X'",X2&" "),"'L'",L2&""),"'Z'",Z2&" "),"'AA'",AA2&" "),"'Imy'",TEXT(I2,"mmmm")&" "&TEXT(I2,"yyyy") ))


MRXLMAY21.xlsm
AB
1ENUMSentence
2E2002Househunting ('I') Airfare 'AC'
3E2004Househunting ('I') Lodging 'L'
4E2007Settling In Service 'X' 'Z'
5E2008Area Tour 'X'
6E2010Homefinding 'X'
7E2020Departure Services 'AC'
8E2021Departure Services Vendor Fee 'AC'
9E2123Home Sale Title Coordination Fees 'AC'
10E2124Home Sale ('I') Inspection ('AA')
11E2438Health Insurance Payment Allowance ('Imy')
Sheet4
 
Upvote 0

Forum statistics

Threads
1,215,472
Messages
6,125,003
Members
449,203
Latest member
Daymo66

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