# LOOKUP FORMULA BASED ON HEADERS

Occasional Contributor

# LOOKUP FORMULA BASED ON HEADERS

Hello,

I have some data, which consists of account numbers (rows) by month (headers).

I'm attempting to create a formula that will return the value of a cell based on the date I enter. For example, if I enter Nov 20, I want the formula to search for that date in the headers and return the values of the account numbers in that column, for Nov 20.

So far I have tried using INDEX & MATCH, VLOOKUP with an MATCH function and SUMIFS, but none of these have worked.

Could anyone suggest any other formulas which may work?

Thanks

9 Replies

# Re: LOOKUP FORMULA BASED ON HEADERS

An actual sample of the spreadsheet itself is better than an image, and would also enable somebody here to write a formula that works and post it for you to use.

# Re: LOOKUP FORMULA BASED ON HEADERS

I have included an example of the spreadsheet, as requested.

I am trying to populate the cells of column N, with the values in column I. I want to use the date in cell P1, as the search criteria. So any the values of any cells contained within a column, where the dates agree are shown in column N.

If you need any further information, please let me know.

Thank you.

# Re: LOOKUP FORMULA BASED ON HEADERS

Enter this formula in cell N2, and copy it down.

=INDEX(B2:M2,,MATCH(\$P\$1,\$B\$1:\$M\$1,0))

To explain the formula: the MATCH function finds the column number in the array of headings that matches your date in P1   The dollar signs keep the references constant even as the total formula is copied to succeeding rows.

The INDEX function uses that number to find the corresponding column in each row as the formula is copied down to succeeding rows.

Let me know if this is in fact doing what you want. I'm curious what the actual application is here. It seems an unusual way to organize the information...so I'm wondering whether the whole spreadsheet or workbook could use a makeover. But of course, it's not my business so feel free to ignore the question.

# Re: LOOKUP FORMULA BASED ON HEADERS

Brilliant, this is now working! When I was using the INDEX & FUNCTION before, I was selecting the entire array, so that must of been why it didn't work.

The application is for use within an a financial statement report. The example I sent shows how the TB data would be formatted within the report.

I'm trying to set it up, so when the user enters the relevant period end date, the formulas will automatically pull in the correct data for the relevant period.

I'm in the process of giving all worksheets and workbooks an efficiency drive makeover, so any input would be very welcome.

# Re: LOOKUP FORMULA BASED ON HEADERS

I'm in the process of giving all worksheets and workbooks an efficiency drive makeover, so any input would be very welcome.

Well, without knowing a lot more it would be entirely presumptuous to offer suggestions. Who the user(s) is (are) going to be for example.

In general, though, the layout you had seemed less than functional for the long term. To keep adding monthly data as a new column works for a while, but there is a limit to columns; and long before that, just navigating the screen becomes unwieldly.

Most databases are better thought of as rows and rows of data with the different fields of distinct types of data reflected in the columns. A set of rows, with both account number and month as separate fields in each row (along with other monthly data) would still be searchable and amenable to summarization by account, by month, by other characteristics ...

# Re: LOOKUP FORMULA BASED ON HEADERS

Bit more modern variant

``=XLOOKUP(\$P\$1, \$B\$1:\$M\$1, B2:INDEX(M:M,XMATCH(,A:A)-1))``

# Re: LOOKUP FORMULA BASED ON HEADERS

I suggest this formula in O2 of the attached version of your file:

``````=INDEX(ColumnsLeft,

ColumnsLeft refers to:

``=Schedule!\$B2:N2``

``=Schedule!\$B\$1:N\$1``

Kindly notice these:

1. I modified the formula starting in C1 to this:

``=EOMONTH(B1,1)``

2. I inserted a column for April 2021, with simulated values thereunder.

3. You can also insert a column for May 2021 to test the dynamic attribute of ColumnsLeft and HeadersLeft.

# Re: LOOKUP FORMULA BASED ON HEADERS

Thank you very much for this example.

This formula will certainly help a lot with making my spreadsheets more dynamic.

# Re: LOOKUP FORMULA BASED ON HEADERS

You're very much welcome!