Why your sheet creates duplicate Google Calendar™ events, and how to stop it
A common first script for Google Sheets™ loops over the rows and calls createEvent() for each one. It works the first time. Run it again, or let a trigger run it, and every event appears twice. Run it a third time and you have three. This page explains why, gives a free Apps Script fix, and lists the cases that fix still doesn't cover.
Why it happens
The script has no memory. Nothing in the sheet records which event a row already created, so on every run it creates a new one. Matching by title and date ("does an event with this name exist that day?") helps a little, but breaks as soon as you rename an event or move it to another day: the old event stays and a new one appears.
The fix: store each event's ID in the row
When the script creates an event, write the event's ID into a spare column. On the next run, if the row has an ID, update that event instead of creating a new one. This version also takes a lock, so two runs that overlap (for example a trigger firing while you run it by hand) can't both create the same event.
/**
* Sync rows to Google Calendar without duplicates.
* Tab "Events": A Title | B Start | C End | D Event ID (leave D empty; the script fills it).
* Format column D as plain text (Format > Number > Plain text).
*/
function syncRowsToCalendar() {
const lock = LockService.getDocumentLock();
if (!lock.tryLock(30000)) return; // another run is still going
try {
const sheet = SpreadsheetApp.getActive().getSheetByName('Events');
const cal = CalendarApp.getDefaultCalendar();
const lastRow = sheet.getLastRow();
if (lastRow < 2) return;
const rows = sheet.getRange(2, 1, lastRow - 1, 4).getValues();
rows.forEach(([title, start, end, id], i) => {
if (!title || !(start instanceof Date) || !(end instanceof Date)) return;
const event = id ? cal.getEventById(id) : null;
if (event) {
event.setTitle(title); // row already has an event: update it
event.setTime(start, end);
} else {
const created = cal.createEvent(title, start, end);
sheet.getRange(i + 2, 4).setValue(created.getId());
SpreadsheetApp.flush(); // save the ID right away
}
});
} finally {
lock.releaseLock();
}
}
To use it: in your sheet choose Extensions → Apps Script, paste the code, save, and run syncRowsToCalendar once to authorise it. To run it automatically, add a time-driven trigger (Triggers → Add trigger). Start and End must be date-time cells.
What this script still doesn't handle
- Changes made in Calendar. It only pushes the sheet to the calendar. Move an event in Google Calendar and the next run moves it back.
- Deleted rows. Delete a row and its event stays in the calendar forever.
- Events deleted in Calendar. Depending on how the event was deleted, the script may create it again or fail on it.
- Only title and time. Description, location, guests, all-day events, repeat rules, colours, reminders and Meet links each need more code.
- Time limits. Apps Script stops a run after 6 minutes. A long sheet needs to save progress and continue on the next run.
- Mistakes. There is no preview of what a run will change and no undo.
- Copied rows. If you copy a row that already has an ID into a new row, both rows point at one event.
The no-code option
Calendupe is a Google Sheets add-on that does the "remember each row's event" part for you, in both directions:
- Each row stays linked to exactly one event, using hidden ID columns and a private tag on the event, so syncing again never makes a duplicate.
- Edits flow both ways: change the row or move the event in Google Calendar, and the other side follows.
- Preview shows what a sync will create, update or delete before anything changes; Undo last sync reverses the last one.
- Events are deleted only when you type
DELETEin a row's status cell. Clearing a row never deletes an event, large deletions ask first, and Find events with no row cleans up events whose rows are gone. - Long sheets continue on the next run, and Google's daily limits are shown before you sync.
Already have duplicates from an old script? Calendupe only manages events it created or that you exported into a sheet, so it won't remove those for you. The easiest clean start is a new calendar: create one in Google Calendar, pick it as Calendupe's default calendar, sync, and then delete the old calendar once you have checked the new one.
Next: set up Calendupe in five minutes.
Get Calendupe on the Marketplace All guides
Calendupe is free during launch, with every feature included. Questions? Email support@calendupe.com.