Apps Script example · 11 min read

Calculate Cap Table Dilution After a Round: Copy-Paste Apps Script Pattern

Working calculate cap table dilution after a round example in Apps Script—copy-paste code, common mistakes, and when to get it built professionally.

SpreadsheetAppManualCap table

Recalculate fully diluted ownership after a priced round including optional option-pool top-up. The workbook becomes the system of record; Apps Script owns the joins and business rules so analysts are not pasting monthly formulas.

Entry point `calcCapTableDilution` reads typed columns with SpreadsheetApp batch APIs. SpreadsheetApp is the primary service; Manual describes how you usually invoke it after authorization.

Keep thresholds (grace days, bands, alert emails, API keys) in Config cells or Script Properties so the same .gs file promotes from sandbox to production without code edits.

This page is technical only: sheet layout, edge cases, runnable code, deploy steps, and FAQs for calculate cap table dilution after a round. No consulting pitch—just the pattern you can paste and harden.

Need this built? Hire a Google Apps Script developer →

Sheet / project setup

TabColumnsNotes
CapTableHolder, Class, SharesPre
RoundPreMoney, Raise, PoolPctTerms
DilutionPost %Output

What this script does

calcCapTableDilution() recalculate fully diluted ownership after a priced round including optional option-pool top-up.

  • Pre/post money
  • New investor shares
  • Pool top-up math

Prerequisites

Container-bound script on the workbook that contains the tabs in the setup table. Authorize SpreadsheetApp scopes on first run.

  • V8 runtime
  • Exact sheet names
  • Script timezone = ops timezone

Walkthrough

Derive price from pre-money/pre-shares, issue new shares for raise, optionally top up pool, rewrite Pre%/Post%.

Paste the code, set Config/Properties, run calcCapTableDilution once, verify the output tab, then attach a Manual trigger.

Edge cases

Pool top-up solves poolShares = p/(1-p)×postShares before pool so post % matches target pool percent.

Testing

Use a sandbox copy with 3–5 known rows. Compute expected outputs for calculate cap table dilution after a round offline, run calcCapTableDilution, and diff the output tab including one intentional bad row.

Hardening

Add LockService around multi-sheet writes if triggers can overlap. Log run timestamps. Keep API keys and alert emails in PropertiesService—not in shared cells.

Variations

Fork ideas: filter to one business unit, change grain (daily→weekly), or POST a summary payload after calcCapTableDilution succeeds.

Operations notes

Assign an owner for the output tab, document regenerate steps, and treat `calcCapTableDilution` as source of truth over ad-hoc cell formulas.

Full code: calcCapTableDilution()

Run calcCapTableDilution when source tabs are current. Edit sheet names and Config/Properties first.

function calcCapTableDilution(){
  const ss=SpreadsheetApp.getActive();
  const cfg=ss.getSheetByName('Round');
  const preMoney=Number(cfg.getRange('B1').getValue());
  const raise=Number(cfg.getRange('B2').getValue());
  const newPoolPct=Number(cfg.getRange('B3').getValue())||0;
  const rows=ss.getSheetByName('CapTable').getDataRange().getValues().slice(1);
  let preShares=0;
  rows.forEach(r=> preShares+=Number(r[2])||0);
  const postMoney=preMoney+raise;
  const price=preMoney/preShares;
  const newShares=raise/price;
  let postShares=preShares+newShares;
  const poolShares=newPoolPct>0? (newPoolPct*postShares)/(1-newPoolPct) : 0;
  postShares+=poolShares;
  const out=rows.map(r=>{
    const sh=Number(r[2])||0;
    return [r[0],r[1],sh, sh/preShares, sh/postShares];
  });
  out.push(['NewInvestor','Preferred',newShares,0,newShares/postShares]);
  if(poolShares) out.push(['OptionPool','Common',poolShares,0,poolShares/postShares]);
  const sh=ss.getSheetByName('Dilution');
  sh.clearContents();
  sh.appendRow(['Holder','Class','Shares','Pre%','Post%']);
  sh.getRange(2,1,out.length+1,5).setValues(out);
  sh.getRange('G1:H3').setValues([['Price',price],['PostShares',postShares],['PostMoney',postMoney]]);
}
  1. Line 1: Entry point — bind triggers to calcCapTableDilution.
  2. Line 7: Batch read; avoid per-cell getValue in loops.
  3. Line 25: Batch write output rows in one setValues call.
  4. Line 5: Rename sheet constants before production.
  5. Line 6: Rename sheet constants before production.

Deploy this example

  1. 01

    Open Apps Script

    In the bound spreadsheet: Extensions → Apps Script. For standalone projects, create one at script.google.com and link your Sheet by ID.

  2. 02

    Paste and save

    Add a .gs file, paste the code below, rename constants at the top (sheet names, column letters, API property keys), then save.

  3. 03

    Authorize once

    Run the main function from the editor. Accept OAuth scopes when prompted — triggers cannot run until authorization succeeds once.

  4. 04

    Add the trigger

    Triggers → Add trigger → choose the handler function and event (time-driven, on edit, or on form submit). Delete test triggers before production.

Before you run: calculate cap table dilution after a round

  • 1Setup tabs exist with headers matching calcCapTableDilution
  • 2Dry-run on a copy workbook
  • 3Timezone verified
  • 4SpreadsheetApp authorization completed
  • 5Output spot-checked against hand calc
  • 6Manual trigger added only after validation
  • 7Owners + alert recipients documented

Frequently asked questions

At minimum the tabs listed in the setup table for Calculate Cap Table Dilution After a Round. Output tabs may be cleared each run—do not store source-of-truth data there.

Run from the Apps Script editor for dry runs. Production usually uses a Manual trigger after OAuth succeeds once.

Pool top-up solves poolShares = p/(1-p)×postShares before pool so post % matches target pool percent.

Per-cell calls burn quota and wall time. One read + one write keeps this pattern under the 6-minute execution cap longer.

PropertiesService (Script Properties) for API keys and alert inboxes. Config sheet is fine for non-secret thresholds.

Simple ratios maybe; calculate cap table dilution after a round needs joins, branching, or side effects (email/Docs/API) that Apps Script handles cleanly.

Keep the .gs in clasp/git. Avoid divergent copies of formulas on the output tab—regenerate from the script.

Related examples

Want this wired into your real workflow?

I adapt these patterns to your Sheet structure, APIs, and triggers — deployed in your Google account. Fixed-scope quotes from $500 · free 30-min consult · quote within 24 hours.