Answers
Answers to common Google Sheets, Excel and Apps Script questions
Problems people regularly ask about in public forums, explained in our own words with a complete fix. Each page links to the public question that inspired it, and script answers are unit-tested.
- Q01
Keep only the newest row per ID (formula)
A single SORTN formula that returns one row per ID or email, always the most recent one, even when the data comes from two ranges.
- Q02
Delete older duplicates (script)
A fast Apps Script that keeps one row per key, the newest by date or by position, and rewrites the sheet in one go instead of deleting rows one by one.
- Q03
onEdit won't send email
A function named onEdit can't send email because simple triggers can't use authorized services. Rename it, add an installable trigger, and it works.
- Q04
Email when a formula result changes
Edit triggers ignore formula recalculations. Save a snapshot of the column and compare it on a timer to email only what changed.
- Q05
Email full Form answers
Google Forms only tells you a response arrived. This short Apps Script emails every answer, with Reply going straight to the respondent.
- Q06
Static timestamp on edit
Formula tricks with NOW() can recalculate later. A small onEdit script writes a fixed date-time the first time a cell is filled, including pasted blocks.
- Q07
Timestamp when a status is chosen
An onEdit script that records the time in another column only when a dropdown changes to one value, such as Shipped, plus how to reuse it across many files.
- Q08
Split names with middle names
TEXTBEFORE and TEXTAFTER formulas that split on the last space, handle one-word names, and keep suffixes like Jr. with the surname.
- Q09
Highlight rows with duplicate values
One conditional formatting formula colors the entire row whenever its value in a key column appears more than once. Variants for repeats only and two columns.
- Q10
XLOOKUP two criteria #N/A
The multiply-the-conditions XLOOKUP pattern for two criteria, how to tell when numbers stored as text are breaking it, and a Google Sheets equivalent.
- Q11
Move a ticked row to another tab
An onEdit script that moves exactly the row you ticked to another tab, instead of sweeping several rows, with safe checks for pastes and unticks.
- Q12
Import all CSVs from a Drive folder
An Apps Script that reads every CSV in a Drive folder, keeps a single header row, skips blank lines and writes everything to one tab in a single call.
- Q13
Daily backup copies
A short Apps Script that saves a dated copy of your spreadsheet to a Drive folder every night and trashes copies older than the newest 30.
- Q14
VLOOKUP/XLOOKUP #N/A when the value is visible
The usual invisible causes of a failed lookup: trailing spaces, numbers stored as text, approximate match without FALSE, and looking left with VLOOKUP, plus copy-paste fixes for Excel and Sheets.
- Q15
Keep notes keyed by ID next to QUERY/FILTER
Manual notes typed next to a live QUERY or FILTER spill stay on fixed rows while the results move. Keep notes in a separate ID-keyed table and look them up.
- Q16
IMPORTRANGE #REF! errors
Why IMPORTRANGE returns #REF!: the sheets aren't connected yet, the URL or range string is wrong, a tab was renamed, the result is too large, cells are in the way, or you can't open the source file.
- Q17
Text dates and DD/MM vs MM/DD
Why imported dates turn into text or swap day and month, why DATEVALUE returns #VALUE!, and formulas that rebuild real dates in Google Sheets and Excel.
- Q18
Apps Script “Exceeded maximum execution time”
Why Google Apps Script stops at 6 minutes, how batching getValues/setValues usually fixes it, and a tested script that pauses before the limit, saves its place and carries on by itself.
- Q19
SUMIFS returns 0: numbers stored as text
SUMIFS, SUMIF and SUM skip numbers stored as text, so the total comes back 0 or too low with no error. How to spot it in one formula, total the column without changing it, and convert it for good. Plus the criteria mistakes that cause the same symptom.
- Q20
ARRAYFORMULA #REF! “would overwrite data”
Why ARRAYFORMULA, FILTER, QUERY and other spilling formulas show #REF! when anything sits in their output area, how to find the blocking cell fast, and how to keep manual overrides without breaking the formula.
- Q21
Conditional formatting colors the wrong rows
Why a custom-formula rule colors the row below, every row or only one column, how the formula is read from the top-left cell of the range, and which dollar signs to use in Google Sheets and Excel.
- Q22
Leading zeros disappear (ZIP codes, IDs)
Why Excel and Google Sheets turn 02108 into 2108 when you type, paste or open a CSV, how to stop it for good, and tested formulas that put the zeros back on codes that already lost them.
- Q23
appendRow writes at the bottom of the sheet
Why appendRow() and getLastRow() skip past hundreds of empty-looking rows when a tab has checkboxes or formulas filled down, and a tested script that writes under the last row of one column instead.
- Q24
Hours total wraps at 24 / overnight shifts
Why a timesheet total over 24 hours shows the wrong number, why a shift that ends after midnight comes out negative or as ######, and tested formulas for overnight shifts, breaks, decimal hours, overtime and pay.
- Q25
onEdit: e is undefined / e.value missing
Why onEdit(e) throws "Cannot read properties of undefined (reading 'range')" when you press Run, why e.value is undefined when several cells change, and a tested onEdit that handles pasted blocks plus a test function that runs it from the editor.
- Q26
SUMIFS between two dates misses the last day
Why a SUMIFS or COUNTIFS date range drops everything from the end date when your dates carry times, the one-line fix, tested month and week totals with EOMONTH and EDATE, and the criteria mistakes that make the total 0.
- Q27
Dependent dropdown on every row
How to make an Item dropdown show only the items for the Category picked in the same row, for every row: a tested Apps Script for Google Sheets that handles pasting and clears stale picks, a no-script helper-row method, and the single Excel list formula.