Overview

If you’ve used them before, I’m sure you’ll agree that dynamic array functions (DAFs) are one of the best features ever to be introduced to Excel. If you haven’t used them yet, please don’t wait any longer (here’s a great resource to get you started!). They allow you to do some truly amazing things that you can’t otherwise do in Excel.

Formulas with DAFs can get a little complex and can take some serious effort to write (even when AI helps!). Accidentally overwriting those formulas – just like any others – is a risk. But you can mitigate that risk with some creative approaches.

In this article, we’ll discuss an approach I’ve found to be super-helpful in protecting those formulas – embedding them in your column headers! Not only will it help prevent your formulas from being overwritten, it will help automate them, and there’s also just a cool factor to it! Make sure to download the example workbook to see some examples you can copy from and use. There’s also a bonus tool at the bottom!

What

So what does it mean to put formulas in the header? It means using the VSTACK function to vertically stack your column header with the formula you want to apply for all the rows in that column.

For this approach to work correctly, your formula must be built to spill results below the header. Hopefully you’re already doing that to some extent! I like to build in a condition to return just one blank value below the cell header if there is no other data that the formula would otherwise work with.

Why

There are three key reasons why you should take this approach:

  1. Your formula results will automatically spill as the hard-coded data is input. No need to worry about filling them down or using unnecessary IF statements to check if they are blank!
  2. Your formula won’t be overwritten if users clear out all the cells below the headers. That can save a ton of time!
  3. It’s a more guided approach for your users, with a certain cool factor. It also showcases the power of DAFs to others who might not otherwise know about them!

This approach is most effective when you have data that includes a mix of hard-coded values (user inputs) and formulas that reference those inputs. Make sure to be clear as to which columns should contain inputs vs. formulas (I like to use different-colored header fill colors) like in the screenshots below.

How

Before you can put your formula in the header, it must be a spilling formula. Instead of referring to just one row, references must refer to as many rows as your data might grow to. Use the dot operator (here’s an article that explains what that is) or an old-school approach (here’s an article that explains how this works). Once your formula is capable of spilling, wrap it in VSTACK like this: =VSTACK(
 "Due day",
 IF($E$2="","",IF(E2:.E5000*$M$1="","",TEXT(WEEKDAY(E2:.E5000*$M$1),"aaaa"))
)
Because the results below the header row are spilling from above, you can’t accidentally clear them – you can only clear the hard-coded data!

Screenshot after clearing data/formula

See the examples below for the before (with a header and formulas) and after (the header embedded in a spilling formula).

Screenshot before applying formulas in the headers

Screenshot after applying formulas in the headers

Bonus

I’ve been taking this approach so much that I ended up making a macro to reduce the clicks and keystrokes. It does two things when you select a header cell with a formula in the cell directly below:
  1. If the formula in the cell below the header is not already spilling, this will convert it to a spilling formula – with the dot operator if supported, and with an alternative approach if not supported.
  2. It will then wrap the existing header text and that spilling formula within VSTACK to embed everything in the header cell.
See the quick clip below for an example:
If for some reason you want to split them out again, simply run it again, and it will prompt you to confirm removing them. See it in action in the quick clip below and learn more at the support page. Want to try out this valuable tool and hundreds of others? Check out the XLEV8 Add-in.

Video

Summary

If you’re looking for a creative way to solve some common Excel formula challenges, this is it. Make sure to grab the example workbook for some examples you can use. Make your formulas dynamic and protect them from accidentally being deleted or changed. Help your users out. And you can do this in one click using the macro above 😉

Do you take some creative approaches like this with your Excel formulas? Let us know with a comment below!

Don't miss great tips, tricks, news, and events!

  • Get our 105 Excel Tips e-book free!
  • Get monthly insights and news
  • Valuable time-saving best practices
  • Unlock exclusive resources

Almost there! We just need to confirm the email address is yours. Please check your email for a confirmation message.