Forum Discussion
Dele65
Dec 30, 2022Copper Contributor
Excel Formula
Hi
I am new to this platform. am also new to excel.
Kindly let me know what is wrong with this formula =SEQUENCE(52, 7, 2023). I wanted to produce 2023 calendar.
thanks
- PeterBartholomew1Silver Contributor
Just in case there is an award for the longest formula, one could have
= LET( startDate, DATE(year, 1, 1), endDate, EOMONTH(startDate, 11), listDates, SEQUENCE(1 + endDate - startDate, 1, startDate), offset, WEEKDAY(startDate, 3), offsetDates, IF(offset, VSTACK(EXPAND("", offset, , ""), listDates), listDates), calendar, WRAPROWS(offsetDates, 7, ""), calendar )
The start date is given. The end date is calculated to allow for leap years. This allows every date of the year to be generated as a single list. Because I want every week to start with a Monday, I used the weekday to offset the dates with a number of blank cells [0 was a bit of a problem]. WRAPROWS changed the list of days to a calendar display of weeks.
My objective is to generate long formulas (no 'rule of thumb' for me!) but with each line being as simple as I can make it.
- Patrick2788Silver Contributor
I believe you'd have to add a 53rd row to show 12/31/2023. If you're building this formula to accommodate future years, 2024 has a leap year so the 53rd row would include (2) 2023 dates.
Try this:
=LET(y,2023,start,DATE(y,1,1),SEQUENCE(53,7,start))
- mtarlerSilver Contributor
Dele65 In addition to the above I assume you want to start on a Sunday so you want to offset that start day accordingly (which this coming year happens to start on a Sun):
=LET(a,DATE(2023,1,1), b,WEEKDAY(a,1)-1, SEQUENCE(53,7,a-b))
EDIT:
I just saw your reply and it sounds like you don't have SEQUENCE function. What version of Excel do you have? If you don't have dynamic arrays (I believe Excel 2021+) then you will need to do something like:
=DATE(2023,1,1)-WEEKDAY(DATE(2023,1,1),1)+1+7*(ROW()-ROW($A$1))+COLUMN()-COLUMN($A$1)
where you enter the Date/Year 2x and the upper left corner of your 'calendar' in 2x (where the $A$1 are located and make sure to include those $) and then fill/copy right and down
- mathetesSilver Contributor
Without knowing exactly what you mean by "produce a 2023 calendar" I suggest that you review this link, from which I've taken the following screen shot
It appears you are wanting
- 52 rows, one for each week;
- 7 columns, one for each day of the week
- but you've not entered a meaningful start date, nor a step
The correct start would be the value of Jan 1 2023, which happens to be 44927. And then the step is 1
So the correct formula would read =SEQUENCE(52,7,44927,1)
An alternative could be=SEQUENCE(52,7,DATEVALUE("1/1/2023"),1)
At the end of the process, when all the fields of 52 rows and 7 columns are filled, make sure they're all formatted as dates, in whichever of the several possibilities you desire.
- Dele65Copper ContributorI appreciate your efforts aimed at helping me to get clear understanding of excel.
i have tried this =SEQUENCE(52,7,44927,1) and =SEQUENCE(52,7,DATEVALUE("1/1/2023"),1) but unfortunately this is the error sign i keep receiving #NAME?
How do i resolve this?- Patrick2788Silver Contributor
You may not have access to SEQUENCE.
Try this formula to see if you can generate 1 to 10. If you get a #NAME error then it's the version.
=SEQUENCE(10)