Forum Discussion
LOOKUP FORMULA BASED ON HEADERS
You could go a long way toward helping us help you by posting a copy (or a representative sample) of your spreadsheet. Your verbal description is confusing.
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.
Thank you for your message.
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.
- TwifooDec 02, 2020Silver Contributor
I suggest this formula in O2 of the attached version of your file:
=INDEX(ColumnsLeft, MATCH(Q$1,HeadersLeft,0))ColumnsLeft refers to:
=Schedule!$B2:N2HeadersLeft refers to:
=Schedule!$B$1:N$1Kindly 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.
- Seaneboy2020Dec 02, 2020Copper ContributorThank you very much for this example.
This formula will certainly help a lot with making my spreadsheets more dynamic.- TwifooDec 02, 2020Silver ContributorYou're very much welcome!
- mathetesDec 02, 2020Silver Contributor
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.
- Phil_VRMay 22, 2023Copper Contributor
Thank you for this formula. One question; I never clearly understood why in some scenarios we have to put two comma's before the match function in this lookup formula.
Thank you,
Phil
- mathetesMay 22, 2023Silver Contributor
Thank you for this formula. One question; I never clearly understood why in some scenarios we have to put two comma's before the match function in this lookup formula.
Assuming your "this formula" is referring to this formula:
=INDEX(B2:M2,,MATCH($P$1,$B$1:$M$1,0))
The reason for the two commas is that after only one comma the value returned by your MATCH refers to a row; after the second comma, it refers to a column. Here is a link that more fully explains the INDEX function, which is the one where it's relevant.
- Seaneboy2020Dec 02, 2020Copper Contributor
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.
Thanks again for your help.
- mathetesDec 02, 2020Silver Contributor
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 ...