I'm in need of some formula assistance in Excel. I'm trying to use the dates in columns G and H (period start date and period end date) to automatically fill out the matrix on the right (columns O through Z) as I have currently manually completed it. For example, if a period starts on 1/1/20 (cell G5) and ends on 6/30/20 (cell H5), I need cells O5:Z5 to show 1, 2, 3, 4, 5, 6, null, null, null, null, null, null. If the period starts on 10/1/20 and ends on 3/31/21, then the cells in O5:Z5 would show null, null, null, null, null, null, null, null, null, 10, 11, 12.
Any help is much appreciated!! Thank you!
I've tried several IF(AND and IF(OR formulas using date references. I've been able to get most of the rows to populate using the following formula, but the problem is the rows with dates that span two years (ex: row 14, which spans 2020 and 2021).
=IF(AND(MONTH(O$4)>=MONTH($G5),MONTH(O$4)<=MONTH($H5)),1,IF(AND(MONTH(O$4)>=MONTH($G5),MONTH($H5)<=12),1,""))
As per my comments above and if i have clearly understood the requirements of your query then, posting it here, to show an example:
• Formula used in cell
O5Or,
To make it more readable and to avoid repeating of formulas you can use
LET()Function.• Formula used in cell
O5Notes:
• The above formulas assume that the cells from
O4:Z4are dates with the first day of each month.• The formula
--TEXT(O$4,"mmm-yyyy")converts the value in cellO$4into a date formatmmm-yyyywhile theTEXT()function formats the date as a string, hence the double unary operator--converts it back to a date serial number. Like wise it has been used for the cells in columnG&H.• Then the formulas compares if
O$4is greater than or equal to the date in$G5and less than or equal to$H5.• If the conditions are met i.e. if its
TRUEthe formula returns the month of the date in cellO$4using theMONTH()Function, while ifFALSEit returns an empty.• However, if the dates in cells
O4:Z4are text then we can change this partFrom -->
To -->
To make it work as per the requirement. Note that the year is hardcoded and assumed to be
2020you use a cell reference to make it dynamic as well.If you are using
MS365then you can use a dynamic spilled array version.• Formula used in cell
O5