How To Autofill Date In Google Sheets

Google Sheets is a versatile tool that allows you to manage and organize data effectively. One of its many features is its ability to autofill data based on patterns you establish. In this blog post, we will discuss specifically how to autofill dates in Google Sheets.

Step 1: Manually Enter the First Two Dates

The first thing you need to do is enter the first two dates manually. This creates a pattern that Google Sheets can recognize and use to autofill subsequent dates. For example, if you want to autofill dates in a weekly pattern, enter the start date in the first cell (say, A1) and the date a week later in the next cell (A2).

Step 2: Select the Two Dates

Next, click and hold on the first cell, then drag down to the second cell to select both dates.

Step 3: Use the Autofill Function

Once you have the two cells selected, move your cursor to the bottom right corner of the selection until it turns into a black cross. This is the autofill handle. Click and drag this handle down the column to the number of cells you want to be autofilled with dates.

Step 4: Verify the Dates

After dragging the autofill handle, release the mouse button. Google Sheets will now autofill the selected cells with dates, maintaining the pattern established by the first two dates. Review these dates to ensure they have been autofilled correctly.

Autofill Dates with a Custom Function

If you want more control over the way your dates are autofilled or need to handle more complex scenarios, you can use a custom function with Google Apps Script.

Here’s an example of a custom function that autofills a date range:

function autoFillDates() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var start = new Date('2021-01-01');
  var end = new Date('2021-01-31');
  var row = 2;
  var column = 1;
  var dates = [];
  
  for (var date = new Date(start); date <= end; date.setDate(date.getDate() + 1)) {
    dates.push([new Date(date)]);
  }
  
  sheet.getRange(row, column, dates.length).setValues(dates);
}

This function will autofill dates from January 1, 2021, to January 31, 2021, in the first column of the active sheet. You can adjust the start, end, row, and column variables to suit your specific needs.

Conclusion

Autofilling dates in Google Sheets can save you a significant amount of time if you often work with spreadsheets containing date data. The process is straightforward, and for more complex scenarios, Google Sheets allows you to use custom functions. Hopefully, this guide has given you a good understanding of how to autofill dates in Google Sheets.