I'm working on a Google Sheets document that contains some very long formulas that are getting hard to read and debug. The formulas are long because I often have to select which formula to execute based on some cell value, then wrap that formula in IF and IFERROR statements to prevent bad values from appearing.
Here's an example: I need to perform a lookup on an ephemeral table constructed from a sheet in the document. I choose the sheet to use for building the ephemeral table based on the value of an adjacent cell.
=IF(F3="", , IFERROR(IF(C3<MinMaraDur, HLOOKUP(F3, {QUERY(RankData, "select K,J,I,H,G,F where A='"&$E3&"' and B='"&$B3&"' and C="&$C3&" and D="&$D3&" and E='"&$G3&"'",0);"III","II","I","CMS","MS","MSIC"}, 2), HLOOKUP(F3, {QUERY(MaraRankData, "select J,I,H,G,F,E where A='"&$E3&"' and B='"&$B3&"' and C="&$C3&" and D="&$D3&"",0);"III","II","I","CMS","MS","MSIC"}, 2)), ))
Crazy, right? I want to put pieces of this formula in cells and construct it using those cells' contents, so (1) it's more readable when I edit this sheet again in 3-6 months, and (2) it's easier to debug by testing each part individually.
How can I accomplish that?