Scroll to Top
💻
Free Code
Users get ready-to-use code at no cost.
📋
Easy Copy
Copy and use the code instantly.
Quick Learning
Understand concepts fast and clearly.
📝
Step-by-Step
Follow simple instructions to implement.
📅 October 1, 2025 💻 Tutorial ⭐ Beginner Friendly

Manage Calendar through GoogleSheet

Author Avatar

Ashish Dwivedi

Editorial Team • Tech Writer

About This Tutorial

Manage Calendar through GoogleSheet
  1. Step 1: Click on the Copy button to copy the code snippet.
  2. Step 2: Paste the copied code into your project’s script editor.

Apps Scripts Blog

Read Blog

📂 javascript
⚡ script1.js
⚡ script1.js
function addCalendarEvent() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var range = sheet.getActiveCell();  // The cell you just edited
  var row = range.getRow();
 
  var task = sheet.getRange(row, 1).getValue(); // Column A: Task
  var date = sheet.getRange(row, 2).getValue(); // Column B: Date (Date object)
  var time = sheet.getRange(row, 3).getValue(); // Column C: Time (Date object or string)
  var statusCell = sheet.getRange(row, 4);      // Column D: Status
 
  if (!date || !time || !task) {
    Logger.log("Missing task/date/time");
    return;
  }
 
  // If time is stored as a Date object (e.g. 10:00 AM), extract hours/minutes
  var startTime = new Date(date); // copy date
  if (time instanceof Date) {
    startTime.setHours(time.getHours());
    startTime.setMinutes(time.getMinutes());
  } else {
    // If time is a string like "10:00", split manually
    var parts = time.split(":");
    startTime.setHours(parts[0]);
    startTime.setMinutes(parts[1] || 0);
  }
 
  var endTime = new Date(startTime.getTime() + 60 * 60 * 1000); // +1 hour
 
  var calendar = CalendarApp.getCalendarById("06fcc75be46e9661bad354847aa07a18a6a9201dde195acb682a3949ae59f695@group.calendar.google.com");
 
  calendar.createEvent(task, startTime, endTime, {
    description: "Created from Google Sheet"
  });
 
  statusCell.setValue("Added ✅");
}