Task guide
Create Calendar events from Sheet rows
Keep one planned event per row in a tab named Events. The script creates the events that have no ID yet and writes the new ID back into the row.
1 · Prepare
Put these pieces in place
- Create a Sheet tab named Events with headers in row 1.
- Put the event title in column A, the start in column B, the end in column C, and leave column D empty for the event ID.
- Format the start and end cells as a date with a time. Select them, then choose Format, Number, Date time. A cell holding plain text cannot be read as a date.
- Use an account whose main Google Calendar is a good place for these new events. Run with one operator, wait for completion, and do not edit or reorder rows during execution.
Change these values
- Sheet tab name
EventsThis must match the tab that holds one planned event per row.
- Calendar
CalendarApp.getDefaultCalendar()This is the main calendar of the account running the script. Swap it for CalendarApp.getCalendarById to use a different calendar.
- Event ID column
4Column D is column number 4. The script writes the new event ID there, and that is what makes a second run skip the row.
2 · Review before running
What the script can access and change
Permissions you approve
- Read and update the Google Sheet that is open.
- See your Google Calendar and add new events to it.
Effects of one run
- Creates one calendar event for each row that has a title, a start, and an empty column D.
- Requests an event ID write in column D after each successful creation. Writing per row records progress so a retry does not repeat event creation; a Sheets-only update should use one batched write instead. Later runs skip visible IDs, but Sheets can buffer writes and an event can exist without a recorded ID after failure. Calendar and Sheets do not share a transaction.
- Only creates events. It never deletes or edits an event that already exists on your calendar.
3 · Copy
Paste this into the Apps Script editor
Create or open a script file, replace the example values marked above, then save the project.
function createCalendarEventsFromSheetRows() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Events');
if (!sheet) throw new Error('Add a Sheet tab named Events before running this function.');
const firstDataRow = 2;
const lastRow = sheet.getLastRow();
if (lastRow < firstDataRow) return;
const calendar = CalendarApp.getDefaultCalendar();
const rows = sheet.getRange(firstDataRow, 1, lastRow - firstDataRow + 1, 4).getValues();
rows.forEach((row, index) => {
const [title, start, end, eventId] = row;
if (!title || !start || eventId) return;
const rowNumber = firstDataRow + index;
const startTime = start instanceof Date ? start : new Date(String(start));
const endTime = end instanceof Date ? end : new Date(String(end));
if (isNaN(startTime.getTime()) || isNaN(endTime.getTime())) {
throw new Error('Row ' + rowNumber + ' needs a date with a time in both the start cell and the end cell.');
}
const event = calendar.createEvent(String(title), startTime, endTime);
sheet.getRange(rowNumber, 4).setValue(event.getId());
});
} 4 · Run safely
Follow these steps in order
Start with one test row
Put headers in row 1. Add a single row below it with a title, a start, and an end, and leave column D empty. Pick a time later today so the new event is easy to find.
Add the script
Open Extensions, choose Apps Script, paste the function over the starter code, and save.
Run it once and approve access
Choose createCalendarEventsFromSheetRows and press Run. Google shows Authorization required. Approve access to the spreadsheet and to your calendar, then open Google Calendar and look for the test event.
Add the remaining rows
When the test event looks right, fill in the other rows and run the function again. Rows that already show an ID in column D are left alone.
5 · Confirm
How to tell it worked
Each finished row shows a long event ID in column D, and the matching events appear on your calendar at the times from columns B and C.
If the result is different
Troubleshooting
- The run fails with "Add a Sheet tab named Events before running this function."
- Rename your tab to Events, or change the name in the code and in the editable values above.
- The run fails with a message about a date with a time.
- Select the start and end cells and choose Format, Number, Date time. Text such as March 4 at 9 is not a date to the script.
- The same event was created twice or a run failed without an ID.
- Stop before rerunning. Inspect the intended calendar around the start and end from that row, comparing the title and time. Reconcile the existing event with column D using its CalendarApp ID before allowing another creation; a browser event URL is not that ID. Resolve uncertain or multiple matches first. Clearing IDs, overlapping runs, and failure after creation can all produce duplicates.
- The event landed on the wrong calendar.
- CalendarApp.getDefaultCalendar() is the main calendar of the account running the script. Replace it with CalendarApp.getCalendarById and the calendar ID from Google Calendar settings.
Technical details
Names used in this script
Open these details when you want to adapt the example or look up an exact service or method name.
Show Apps Script symbols and service pages
Apps Script symbols
Service pages
Keep going
Related tasks, basics, and apps
- Task guide Email yourself tomorrow’s calendar agenda
A setup function installs one daily trigger for the early evening. Each evening the script reads tomorrow on your main calendar and emails you the list.
- Task guide Send an email for each row in a Google Sheet
Use one row per person, then let the script send only the rows that have not already been marked as sent.
- Object reference Sheet
A Sheet is one tab inside a Google spreadsheet. Reach it with getSheetByName() or getActiveSheet(), then inspect getLastRow() or read cells with getRange().
- Object reference Range
A Range represents one cell such as A2 or a rectangular block of rows and columns in a Sheet. Use getValue() for one cell and getValues() or setValues() for a 2D array of rows.
- Object reference Calendar
A calendar holds a set of events. Most scripts use your default calendar, but you can also open another calendar you have access to by its ID.
- Object reference Calendar event
A calendar event is one entry on a calendar, such as a meeting or a reminder. It carries a title, a start and end time, and an optional guest list.
- Basics Dates, time zones, and Utilities.formatDate
A Date holds one instant in time. Use Utilities.formatDate(date, timeZone, pattern) and Session.getScriptTimeZone() to format it in the right time zone.
- Google app Google Sheets
SpreadsheetApp lets a Google Sheets script read a Sheet or Range, add a custom menu or formula, and run repeatable actions across rows.
- Google app Google Calendar
CalendarApp scripts read events on a date with getEventsForDay() and add new CalendarEvent entries with createEvent() after you approve Calendar access.