Sub topic 12
Limits and troubleshooting failed imports
This chapter assumes you have already used File > Import, understand the import location options (new sheet, replace, append), and know the type pitfalls from earlier in the tutorial. You should also be comfortable with TRIM, TEXT, and the Apps Script import routine. Here you will learn which limits stop an import, how to read the symptoms of a failed one, and how to work out the cause in a fixed order.
Two kinds of failure
Imports fail in two different ways, and they need different fixes.
- Loud failures. Sheets shows an error message, a
#N/Aor#REF!value, or a spinner that never ends. Usually a limit was hit or the source could not be reached. - Silent failures. The import finishes, but the data is wrong. Examples are shifted columns,
éwhereéshould be, dates swapped between day and month, or missing leading zeros. These are more dangerous because nothing warns you.
Earlier chapters covered the silent failures in detail. This chapter lists them again in a symptom table so you can find the right fix quickly.
Limits that stop an import
Google changes these figures from time to time. Check the current Google Workspace documentation before you plan around a number near the edge.
| Limit | Typical value | What happens when you reach it |
|---|---|---|
| Cells per spreadsheet (all sheets together) | 10 million | The import is refused or only partly applied, with a message about the cell limit |
| Columns in one sheet | 18,278 (column ZZZ) | Extra columns are dropped or the import fails |
| Size of an uploaded file that Drive converts to Sheets | About 100 MB | Drive keeps the file as an uploaded file and cannot open it as a Google Sheet |
| Apps Script run time per execution | About 6 minutes | The script stops partway through |
| `IMPORTDATA` result size and refresh | Limited size, cached for a period | `#N/A` with a size error, or stale data |
The 10 million cell limit counts every cell in the workbook, including empty cells in sheets you already created. A new sheet starts with 1,000 rows and 26 columns, which is 26,000 cells, even before you add data. If you keep many tabs, each one uses part of the budget.
A rough check before importing a large CSV: multiply the row count by the column count. Compare that product to 10 million minus the cells already in use. Importing 400,000 rows with 30 columns needs 12 million cells, so it cannot fit into one workbook however you load it.
Working around size limits
You have a few options when a file is too large.
- Split the file. Cut it into several CSV files by date range or category, and import each into its own spreadsheet.
- Drop columns you do not need. Remove them from the source file before importing. Cells you never import are cells you never pay for.
- Pre-aggregate. Summarize the data in a database or script, then import the summary.
- Use a different tool. For analysis on tens of millions of rows, a database or BigQuery is a better home than a spreadsheet.
Trimming empty rows and columns after an import also gives cells back. Select the unused rows, right-click, and choose Delete rows. Unused grid space counts toward the limit.
A fixed order for diagnosing problems
Most import problems come from one of five places: the file, the dialog settings, the encoding or locale, the cell types, or the method you chose. Check them in this order, because each step is cheap and rules out a whole class of causes.
Read the diagram from the top. Do not change several settings at once. Change one, re-import, and look at the result. Otherwise you will not know which change fixed it.
Symptom table for silent failures
| Symptom | Likely cause | Fix |
|---|---|---|
| Whole rows land in column A | Wrong separator type | Re-import and pick the correct separator, or use Data > Split text to columns |
| Columns shift partway down the sheet | Unquoted commas inside text fields | Fix the source file so those fields are quoted, or use a different delimiter |
| `é`, `’`, or `?` in text | Wrong character encoding | Re-save the file as UTF-8 and import again |
| `3/4/2025` read as March 4 when you meant 3 April | Spreadsheet locale differs from the file | Change File > Settings > Locale, then re-import |
| `1.234,56` becomes text | Locale uses a different decimal mark | Set the locale to match the file |
| `00123` shows as `123` | Conversion to numbers is on | Re-import with conversion off, or format the column as plain text first |
| Long IDs show as `1.23457E+15` | Large number converted | Import as text, and format the column as plain text |
| Text cell looks the same as another but lookups fail | Extra spaces | Clean with `TRIM` |
| Formulas show `#NAME?` after converting Excel | Function with no Sheets equivalent | Replace the function or rebuild the logic |
If several symptoms appear together, start with the separator, then encoding, then locale. A wrong separator hides every other problem, and a wrong encoding corrupts text before type conversion happens.
Converted Excel workbooks that behave differently
Importing or converting an .xlsx file can run without any error and still change the workbook. Check these things after conversion:
- Macros. VBA code is not carried over. Rewrite the logic in Apps Script if you need it.
- Charts and pivot tables. Some are kept in simplified form and some are lost. Open each and compare it to the original.
- Formulas. Functions that Sheets does not support show
#NAME?. Data-table features such as what-if tables do not convert. - External links. References to other workbooks stop working. Replace them with
IMPORTRANGEor paste the values. - Formatting. Custom fonts, some conditional formatting rules, and some number formats may change.
A good habit is to keep the original .xlsx file untouched and compare totals. If a column's sum in Excel is 48,210.50, the same column in Sheets should give the same total. A mismatch usually means text-formatted numbers or rows that were dropped.
Troubleshooting IMPORTDATA
IMPORTDATA is simple, so its failures follow a few patterns.
- The URL does not return raw CSV. If the address opens a web page with a download button,
IMPORTDATAreceives HTML, not data. Use the direct file address. - The file needs a login. The function fetches the URL without your Google credentials. A file in your private Drive, or on a site that needs sign-in, fails with a "could not fetch" or "not found" style error. The URL must be reachable by anyone.
- The format is wrong.
IMPORTDATAreads CSV and TSV text. It cannot read an.xlsxfile, because that is a zipped binary format. For Excel files, upload to Drive and open or convert them. - The delimiter is wrong. If everything lands in one column, pass the delimiter as the second argument, for example
;. - The result is large. Very large files return a size error. Split the source or switch to a script.
- The data looks old. Results are cached for a while. Wait, or change the URL slightly with a query parameter such as
?v=2if the server ignores it.
The formula below tests the delimiter. If the result lands in one column, the separator is wrong:
=IMPORTDATA("https://example.com/data.csv", ";")If the formula's output would overwrite cells that already hold data, you get a #REF! error that says the array result was not expanded. Clear the cells to the right and below the formula.
Troubleshooting the Apps Script import
Scripts fail in ways that the dialog does not. The most common are listed here.
- Ragged rows.
Utilities.parseCsvcan return rows with different lengths when a file has short lines.setValuesneeds a rectangular array, so a mismatch raises an error about the number of columns not matching the range. Pad each row to the widest row. - Byte order mark. Some tools save UTF-8 files with a leading marker character. It can end up glued to the first header, so a lookup on that header fails. Strip it.
- Type conversion in
setValues. Strings such as00123are parsed as if you typed them, and become the number 123. Set the range's number format to plain text (@) before writing if you want to keep them. - Run time. A script that processes very large files may reach the execution limit. Write in one
setValuescall, not row by row, because every extra call to the spreadsheet service costs time. - Wrong file.
getFileByIdfails when the ID is wrong or you lack access. Copy the ID from the file's URL.
Here is a hardened version of the earlier routine:
function importCsvSafely() {
const fileId = 'YOUR_FILE_ID';
let text = DriveApp.getFileById(fileId).getBlob().getDataAsString('UTF-8');
text = text.replace(/^\uFEFF/, ''); // remove a leading byte order mark
const rows = Utilities.parseCsv(text);
if (rows.length === 0) {
throw new Error('The file contains no rows.');
}
// Pad short rows so the array is rectangular.
const width = rows.reduce((max, row) => Math.max(max, row.length), 0);
const padded = rows.map(row => row.concat(new Array(width - row.length).fill('')));
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('Imported') || ss.insertSheet('Imported');
sheet.clearContents();
// Plain text format keeps leading zeros and long IDs exactly as written.
sheet.getRange(1, 1, padded.length, width)
.setNumberFormat('@')
.setValues(padded);
Logger.log('Imported %s rows and %s columns.', padded.length, width);
}The log line gives you a quick check against the source. If the file has 12,000 data rows plus a header, the log should say 12,001 rows. Open View > Logs (or Executions) in the Apps Script editor to read it.
Because everything is written as text, numbers will not sum until you convert them. You can convert one column at a time with =VALUE(A2) or =ARRAYFORMULA(VALUE(A2:A)), and leave ID columns as text.
Verify the import before you trust it
Failed imports that look successful are only caught by checking. After any import, compare at least three things with the source:
- Row count. In Sheets,
=COUNTA(A:A)counts non-empty cells in column A. Compare it with the line count of the file. - A numeric total. Sum one numeric column and compare with the same total from the source.
- A few edge rows. Look at the first row, the last row, and any row with accents, quotes, or empty fields.
For text cleanup, =ARRAYFORMULA(TRIM(A2:A)) removes extra spaces, and =TEXT(A2, "00000") restores five-digit codes. Cleaning formulas belong in a separate column or sheet. Once they look right, copy the results and use Paste special > Values only, so the original import stays recoverable until you are sure.
Summary of habits that prevent failed imports
- Estimate cell counts before importing large files.
- Check the file in a plain text editor first. You can see the real separator, quoting, and encoding.
- Import one change at a time and compare totals.
- Keep the original file and the raw import untouched.
- Choose the method to fit the job: the dialog for one-off files,
IMPORTDATAfor small public CSVs, and a script for repeated or controlled imports.
Exercise
You import a 250,000-row CSV with 45 columns into a workbook that already has three sheets of 26,000 cells each, and Sheets refuses the import. Calculate whether the data could fit, name one way to make it fit, and explain what you would check after importing to be sure no rows were lost.
Show answer
The new data needs 250,000 × 45 = 11,250,000 cells, which is already over the 10 million cell limit before counting the 78,000 cells in the existing sheets. It cannot fit as is. Reduce the cell count by splitting the file into parts (for example two files of about 125,000 rows, each in its own spreadsheet), by removing unneeded columns from the source, or by aggregating the data first. For example, keeping 20 columns gives 5,000,000 cells, which fits alongside the existing sheets. After importing, compare the row count (=COUNTA(A:A) against the file's line count minus the header if one exists), compare the sum of a numeric column with the source total, and look at the first and last rows.
Exercise
An Apps Script import raises an error that the data has a different number of columns than the target range, and the first header does not match a lookup even though it looks right. Name the two likely causes and the fix for each.
Show answer
First, the CSV has short rows, so Utilities.parseCsv returns rows of different lengths and setValues needs a rectangular array. Fix it by finding the widest row and padding every other row with empty strings. Second, the file starts with a byte order mark that is attached to the first header cell, so the text is not what it appears to be. Fix it by removing the leading \uFEFF character from the text before parsing, for example with text.replace(/^\uFEFF/, '').