ちいさな自動化工房 (Chiisana Automation Workshop) — sample page

Sample: fixing Google Sheets formulas and Apps Script errors

This is a sample. All sheets, names and numbers below are made up for this page. No client data or client work is shown. Each case shows a common problem, what it looked like before, and the fix after. I write and check each fix with generative AI tools, then run it on a copy of the sheet with dummy data before delivery.
見本のページです。表・名前・数字はすべて架空で、実在のお客様のデータや成果物は使っていません。修正は生成AIで作成・確認し、ダミーデータの写しで動かしてから納品します。

Case 1 — VLOOKUP returns the wrong price

An order sheet looks up unit prices from a price list. Some rows show a price, but it is the price of a different product.

AB
Prices sheet, row 1ProductUnit price
row 2Pen-Blue120
row 3Notebook-A5300
row 4Eraser80

Orders sheet, A2 = "Stapler" (a new product not yet in the price list), A3 = "Eraser".

Before
=VLOOKUP(A2, Prices!A:B, 2)

Order "Stapler" (not in the list) shows 80 (the price of Eraser) instead of an error.

After
=IFERROR(VLOOKUP(TRIM(A2), Prices!A:B, 2, FALSE), "not in price list")

"Stapler" shows not in price list; "Eraser" shows 80.

Why it broke: without the 4th argument, VLOOKUP assumes the first column is sorted A→Z and returns the closest row at or before the search value. The price list was not sorted, so a missing or misspelled name can get another product's price instead of an error. FALSE forces an exact match, TRIM removes stray spaces, and IFERROR makes missing items visible.
4番目の引数を省くと「並べ替え済み」とみなされ、近い行の値が返ります。完全一致(FALSE)にして、見つからない商品は文字で知らせる形にしました。

Case 2 — Monthly total shows 0

A sales log has dates in column A and amounts in column C. The November total is 0 although there are November rows.

Before
=SUMIFS(C:C, A:A, ">=2026/11/01", A:A, "<2026/12/01")

Result: 0. The dates came in from another system as text ("2026/11/05"), not as real dates (they sit left-aligned and =ISNUMBER(A2) is FALSE).

After
=IFERROR(SUM(FILTER(C2:C, IFERROR(DATEVALUE(A2:A), 0) >= DATE(2026,11,1), IFERROR(DATEVALUE(A2:A), 0) < DATE(2026,12,1))), 0)

Result: the real November total. Longer term fix: convert column A to real dates once (a helper column with =DATEVALUE(A2), then Paste special → Values only and Format → Number → Date), so a plain SUMIFS works again.

Why it broke: comparisons like ">=" only match real dates (numbers). Text that looks like a date is skipped, so every row was ignored.
日付が文字として入っていたため、条件に一致する行が0件でした。文字の日付を変換して集計する式にし、元の列を本物の日付に直す手順もお渡しします。

Case 3 — Apps Script stops with an error

A script copies "approved" rows to an archive sheet. It stops with an error as soon as it finds an approved row.

Before
function archive() {
  const src = SpreadsheetApp.getActive().getSheetByName('Requests');
  const dst = SpreadsheetApp.getActive().getSheetByName('Archive');
  for (let r = 2; r <= src.getLastRow(); r++) {
    if (src.getRange(r, 4).getValue() === 'approved') {
      const row = src.getRange(r, 1, 1, 4).getValues();
      dst.getRange(dst.getLastRow() + 1, 1, 1, 5).setValues(row);
    }
  }
}

Exception: The number of columns in the data does not match the number of columns in the range. The data has 4 but the range has 5.

Even with the column count fixed, reading one cell per row gets slow on large sheets and can hit the 6-minute limit (Exceeded maximum execution time).

After
function archive() {
  const ss = SpreadsheetApp.getActive();
  const src = ss.getSheetByName('Requests');
  const dst = ss.getSheetByName('Archive');
  const last = src.getLastRow();
  if (last < 2) return;
  const rows = src.getRange(2, 1, last - 1, 4).getValues()
    .filter(r => String(r[3]).trim().toLowerCase() === 'approved');
  if (rows.length === 0) return;
  dst.getRange(dst.getLastRow() + 1, 1, rows.length, 4)
    .setValues(rows);
}

Reads the sheet once, filters in memory, writes once, however many rows there are.

Why it broke: the target range was 5 columns wide but each row had 4 values, and reading one cell at a time inside a loop gets slow as the sheet grows. Matching "approved" case-insensitively also catches "Approved " typed by hand.
書き込み先の列数(5)とデータの列数(4)が合わずに止まっていました。1セルずつ読む形を、まとめて読んでまとめて書くように直し、行が増えても時間がかかりにくくしました。

How a fix is delivered

Sample page — ちいさな自動化工房. Made-up data only.