Skip to content

Instantly share code, notes, and snippets.

@al-codaio
al-codaio / count_colored_cells_google_apps_script.js
Created February 27, 2023 03:09
Count the number of cells with a background color in Google Sheets (Google Apps Script)
function CountFormattedCells() {
// Output the number of formatted cells somewhere in your spreadsheet
var outputNumberOfFormattedCells = 'C52'
// Cell that contains the color you want to count. Default is blank.
var cellWithFormatToCount = ''
var spreadsheet = SpreadsheetApp.getActive();
var currentRangeColors = spreadsheet.getActiveRange().getBackgrounds();
@al-codaio
al-codaio / loading_bar.js
Created April 13, 2021 18:19
Create a loading bar while you're retrieving results from an API with Google Apps Script
// Create a loading bar in your Google Sheet using Google Apps Script
// Author: Al Chen (al@coda.io)
// Last Updated: April 13th, 2021
// Notes: Assumes you are using the V8 runtime (https://developers.google.com/apps-script/guides/v8-runtime)
// Example Google Sheet: https://docs.google.com/spreadsheets/d/1ngvYKEMunqCVufR10rlK42iENAERp-uyiPN_aiq-MKo/edit?usp=sharing
SOURCE_SHEET_ID = 'YOUR_GOOGLE_SHEETS_ID'
SOURCE_WORKSHEET_NAME = 'YOUR_WORKSHEET_NAME'
function loop() {
@al-codaio
al-codaio / peloton_coda_sync.js
Last active December 11, 2021 18:52
Google Apps Script to sync Peloton workout data to a table in a Coda doc
// One-way data sync from Peloton API to Coda in Google Apps Script
// Author: Al Chen (al@coda.io)
// Last Updated: December 11th, 2021
// Notes: Assumes you are using the V8 runtime (https://developers.google.com/apps-script/guides/v8-runtime)
// Coda's library for Google Apps Script: 15IQuWOk8MqT50FDWomh57UqWGH23gjsWVWYFms3ton6L-UHmefYHS9Vl
// Writeup and copyable template here: https://coda.io/@atc/analyze-your-peloton-workout-stats-with-real-time-updates
//////////////// Setup and global variables ////////////////////////////////
CodaAPI.authenticate('YOUR_CODA_API_KEY')
@al-codaio
al-codaio / peloton_coda_sync.py
Last active January 21, 2021 17:42
Python script to sync Peloton workout data to a table in a Coda doc
# One-way data sync from Peloton API to Coda in Python
# Author: Al Chen (al@coda.io)
# Last Updated: January 21st, 2021
# Writeup and copyable template here: https://coda.io/@atc/analyze-your-peloton-workout-stats-with-real-time-updates
################# Setup and global variables ###########
api_key = 'YOUR_CODA_API_KEY'
coda_doc_id = 'YOUR_CODA_DOC_ID'
peloton_username = 'YOUR_PELOTON_USERNAME'
@al-codaio
al-codaio / google_sheets_fill_values_down.js
Last active February 20, 2023 17:53
Fill cell value down until a new cell value occurs - Google Apps Script for Google Sheets
// Google Apps Script to take a value in column A and fill it down until a new value shows up in a cell for Google Sheets
// Author: Al Chen (al@coda.io)
// Last Updated: September 6th, 2020
// Video tutorial: https://youtu.be/t-32QkyjKVE?t=106
function fillValuesDown() {
var spreadsheet = SpreadsheetApp.getActive()
var currentRange = spreadsheet.getRange("A2:A" + spreadsheet.getLastRow())
var newRange = []
var newFillValue
@al-codaio
al-codaio / msexcel_fill_values_down.vba
Last active October 31, 2021 02:01
Fill cell value down until a new cell value occurs - VBA script for Microsoft Excel
' VBA script to take a value in column A and fill it down until a new value shows up in a cell for Microsoft Excel
' Author: Al Chen (al@coda.io)
' Last Updated: September 6th, 2020
' Video tutorial: https://youtu.be/t-32QkyjKVE?t=1109
Sub fillValuesDown()
Dim lastRow As Double
lastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
Dim currentRange As Variant: Set currentRange = ActiveSheet.Range("A2:A" & lastRow)
ReDim newRange(1 To lastRow)
@al-codaio
al-codaio / google_doc_to_coda_one_way_sync.js
Last active August 28, 2020 13:01
Takes all your Google Docs in a Google Drive folder, takes the first table in each Google Doc, and syncs that data to a table in Coda.
// Google Apps Script for one-way data sync from a table in a Google Doc to Coda table from multiple Google Docs in a Google Drive folder
// Author: Al Chen (al@coda.io)
// Last Updated: August 6th, 2020
// Notes: Assumes you are using the V8 runtime (https://developers.google.com/apps-script/guides/v8-runtime)
// Coda's library for Google Apps Script: 15IQuWOk8MqT50FDWomh57UqWGH23gjsWVWYFms3ton6L-UHmefYHS9Vl
//////////////// Setup and global variables ////////////////////////////////
CodaAPI.authenticate('YOUR_API_KEY')
@al-codaio
al-codaio / google_sheets_coda_one_way_sync.js
Last active July 16, 2020 20:32
One-way data sync from Google Sheets to a table in Coda (Google Apps Script)
// One-way data sync from Google Sheets to Coda using Google Apps Script
// Author: Al Chen (al@coda.io)
// Last Updated: July 16, 2020
// Notes: Assumes you are using the V8 runtime (https://developers.google.com/apps-script/guides/v8-runtime)
// Coda's library for Google Apps Script: 15IQuWOk8MqT50FDWomh57UqWGH23gjsWVWYFms3ton6L-UHmefYHS9Vl
//////////////// Setup and global variables ////////////////////////////////
CodaAPI.authenticate('YOUR_API_KEY')
@al-codaio
al-codaio / coda_google_sheets_one_way_sync.js
Last active November 7, 2022 03:30
One-way data sync from a Coda table to a worksheet in Google Sheets (Google Apps Script)
// One-way data sync from Coda to Google Sheets using Google Apps Script
// Author: Al Chen (al@coda.io)
// Last Updated: July 16, 2020
// Notes: Assumes you are using the V8 runtime (https://developers.google.com/apps-script/guides/v8-runtime)
// Coda's library for Google Apps Script: 15IQuWOk8MqT50FDWomh57UqWGH23gjsWVWYFms3ton6L-UHmefYHS9Vl
//////////////// Setup and global variables ////////////////////////////////
CodaAPI.authenticate('YOUR_API_KEY')
SOURCE_DOC_ID = 'YOUR_SOURCE_DOC_ID'
@al-codaio
al-codaio / google_sheets_one_way_sync.js
Created May 20, 2019 16:34
One-way data sync between Google Sheets files
var sourceSpreadsheetID = "TO UPDATE";
var sourceWorksheetName = "TO UPDATE";
var targetSpreadsheetID = "TO UPDATE";
var targetWorksheetName = "TO UPDATE";
function importData() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
//Uncomment line 11 below and comment out line 9 if you want to sync a named range. Replace "teamBugs" with your named range.