Is there a way to pretty print Excel formulas?
I’ve got a few worksheets of semi-complex formulas to slog through, so this would make my life a bit easier.
I’m just looking to turn something like this
AC6+AD6+(IF(H6="Yes",1,IF(J6="Yes",1,0)))+IF(X6="Yes",1,0)
into something more readable without manually doing it in Vim or the like. Excel does do color-matching on the parentheses, but it’s still all mashed together on one line.
This VBA code will win no awards, but it’s O.K. for quickly looking at typical formulas. It just does what you’d do with parens or separators manually. Stick it in a code module and call it from the VBA immediate window command line. (EDIT: I had to look at some formulas recently, and I improved on what was here from my original answer, so I came back and changed it.)
If you call it like so:
you don’t have to worry about escaping your double quotes and so on. You’ll get output that looks like this:
You can also call it with a plain string.