Search code examples
google-sheetsarray-formulasgoogle-sheets-formula

Set dates in range dependent on first date of range


Let's say I have a horizontal range of cells in google sheets - format: date. I go to the first two cells and set the first two days of a month, grab the blue dot and drag it all over to the right so it fills the columns with all dates of the month consecutively.

However, if I want to change the month I would have to repeat the process. How do I set this up so that when I double click the first cell, open the date picker and set it to a different month, all the other cell dates change accordingly to the new month INCLUSIVE the correct amount of columns to be filled according to the number of dates of the month. So when I set from Jan to Feb I don't have three columns left over from Jan.

Wondering if there is a solution without a script - I feel there is one.


Solution

  • =ARRAYFORMULA(TRANSPOSE(TO_DATE(ROW(
     INDIRECT("A"&DATE(YEAR(A1), MONTH(A1), DAY(A1)+1)):
     INDIRECT("B"&EOMONTH(A1, 0))))))
    

    enter image description here