When working with any Excel function that goes more than a few levels deep, it quickly becomes hard to read in the single-line format Excel presents them in:
=IF(F3,24*IF(AC3,IF(ROW()=16,V3,MIN(IF(OR(1440*SUMIF(AC3:AC$16,TRUE,U3:U$16)>=1440*V3,NOT(AC3)),U3,IF(1440*SUMIF(AC3:AC$16,TRUE,Z3:Z$16)>=1440*V3,Z3,AA3)),V3)),U3),"")
So what I'll often do is, I'll pop it into Sublime and indent it like code, making it immediately easier to analyze:
=IF(
    F3,
    24*IF(
        AC3,
        IF(
            ROW()=16,
            V3,
            MIN(
                IF(
                    OR(
                        1440*SUMIF(AC3:AC$16,TRUE,U3:U$16)>=1440*V3,
                        NOT(AC3)
                    ),
                    U3,
                    IF(
                        1440*SUMIF(AC3:AC$16,TRUE,Z3:Z$16)>=1440*V3,
                        Z3,
                        AA3
                    )
                ),
                V3
            )
        ),
        U3
    ),
    ""
)
I've done this enough times that it would save me time to automate it. I started trying to write a regex to do it, something along the lines of:
find ((?: {4})*)(.*?)\b(IF|AND|OR|MIN|MAX)\( replace \1\2\3(\n    \1
But I couldn't get it to work because regex struggled with the recursive indentation. I found a Sublime package that can bundle a series of separate regexes into a single operation, which might work but I'm not sure how I'd approach it.
How can I auto-indent my code like this? Are there any possible alternate approaches I may not know about?
 
    