Key Takeaways
- FILTER splits the eight row sample into three North rows and five South rows without copying by hand.
- The Apps Script version writes one sheet per region and logs the row count of each.
- VSTACK puts the two parts back together in a single table with one header row.
- Only values survive a CSV export, so formulas must be pasted as values before download.
You can split one CSV into two regional files and merge them back without copying rows by hand.
| Step | Exact formula or menu path |
|---|---|
| Split the North rows | =FILTER(All!A2:D9, All!C2:C9="North") on a new tab |
| Merge the two tabs | =VSTACK(North!A1:D4, South!A2:D6) on a Merged tab |
What you should see: three North rows, five South rows and a Merged tab with one header and eight data rows.
What You Will Split and Merge
One CSV contains orders from two regions. You will split it into two files for two colleagues, then merge their corrected versions back into one table. Every formula and script below runs on the same eight rows.
The CSV and every formula stay inside your own Google Sheet. If you only need to edit a CSV in place, a free CSV editor inside Google Sheets covers that job.
Eight Sample Rows
| Order ID | Customer | Region | Amount |
|---|---|---|---|
| 1001 | Acme Corp | North | 120 |
| 1002 | Globex Ltd | South | 85 |
| 1003 | Initech | North | 200 |
| 1004 | Umbrella Ltd | South | 75 |
| 1005 | Northwind Traders | North | 310 |
| 1006 | Hooli | South | 95 |
| 1007 | Soylent Corp | South | 140 |
| 1008 | Stark Industries | South | 260 |
Split by Rows With FILTER
Import the CSV into a sheet called All with headers in row 1. Create a tab called North and enter in A1:
=FILTER(All!A2:D9, All!C2:C9="North")
Create a second tab called South and change the criterion to "South". Add the header row by copying A1:D1 from the All tab into each new tab.
For a split by position instead of value, use =ARRAY_CONSTRAIN(All!A2:D9,4,4) for the first four rows and =OFFSET(All!A2,4,0,4,4) for the last four.
Split by Column With Apps Script
Open Extensions, Apps Script, paste the function and run splitByRegion. It reads the active sheet and creates one tab per distinct region.
/**
* Creates one sheet per value in column C of the active sheet.
* @returns {number} The number of sheets created.
*/
function splitByRegion() {
const book = SpreadsheetApp.getActiveSpreadsheet();
const source = book.getActiveSheet();
const values = source.getDataRange().getValues();
const header = values[0];
const groups = {};
for (let i = 1; i < values.length; i++) {
const key = String(values[i][2]);
if (!groups[key]) groups[key] = [header];
groups[key].push(values[i]);
}
Object.keys(groups).forEach(function (key) {
const name = key.slice(0, 100);
const target = book.getSheetByName(name) || book.insertSheet(name);
target.clear();
const rows = groups[key];
target.getRange(1, 1, rows.length, header.length).setValues(rows);
Logger.log(name + ": " + (rows.length - 1) + " rows");
});
return Object.keys(groups).length;
}
Merge With VSTACK
On a new tab called Merged, enter:
=VSTACK(North!A1:D4, South!A2:D6)
The first range carries the header row and the second starts at row 2. Including both headers would leave a repeated header inside the data, which downstream imports often treat as a record.
Select the merged range, copy it and use Paste special, Values only into a fresh tab before choosing File, Download, Comma separated values. A CSV cannot hold the VSTACK formula.
Expected Outputs
After the split, the North tab holds three data rows: 1001 Acme Corp, 1003 Initech and 1005 Northwind Traders. The South tab holds five data rows: 1002 Globex Ltd, 1004 Umbrella Ltd, 1006 Hooli, 1007 Soylent Corp and 1008 Stark Industries. The script log shows North: 3 rows and South: 5 rows.
After the merge, the Merged tab has one header and eight data rows in the original order within each region. A count check with =COUNTA(Merged!A:A)-1 returns 8, which confirms that nothing was lost in the round trip.
Frequently Asked Questions
How do I split a CSV by a column value?
Import the CSV, then use =FILTER(All!A2:D9,All!C2:C9="North") on a new tab. In the worked example that returns three rows for North and five for South.
How do I merge two tabs back into one file?
Use =VSTACK(Sheet1!A1:D4,Sheet2!A1:D6) on a third tab, then download that tab as CSV. VSTACK keeps one header if you include it only in the first range.
Can Apps Script split a file automatically?
Yes. The script on this page reads the active sheet, groups rows by the region column and writes one new sheet per group. It prints the row count for each output.
What does the split not preserve?
Formatting and formulas that reference other sheets. Export values only if the receiving system expects plain CSV data.
You Might Also Like
About the Author
Andrew Apell is the creator of Flookup Data Wrangler and has built data cleaning tools for Google Sheets since 2018.
Every Flookup result described here can be checked in the documentation.
Read
Our Story
for the background or
contact the team
with any questions about this post, including corrections, unclear steps or use cases we have not covered yet.