• Got Sheet
  • Posts
  • 13 Lines of Code to Wrangle CSV Files

13 Lines of Code to Wrangle CSV Files

A Little Apps Script Goes a Long Way

RESOURCES

Some tools to make life easier. You’re welcome :)

  • beehiiv - my choice for a newsletter operating system

  • Coefficient - Live connections to 60+ business systems

  • Lido - Automate your spreadsheets; accurately extract date from PDFs

  • TransactionPro - quickly import, export or delete data in Quickbooks

  • Perspective - Build high-converting lead funnel microsites

  • Gamma - AI designer for presentations, websites, social posts, and more

  • Gratitude Plus - social gratitude journal

  • Senja - collect and display testimonials

  • OpusClip - turn long videos into short clips

  • Carrd - free one-page website builder

  • Notion - notetaking + project management + database

  • Transistor - my favorite podcast host

  • Fathom - AI-powered notetaking app

MAIN ARTICLE

A Quick Overview

CSV files tend to pile up from all directions. Sales data, customer feedback, inventory reports – they need to be combined into one master spreadsheet for analysis or reporting.

The standard approach involves opening each file, copying the data, and pasting it into a master workbook. This process scales poorly as the number of files increases, and manual copying introduces opportunities for errors.

A better approach is automating this process entirely.

There's a Better Way

Most CSV combining solutions either cost money, require new software, or involve complex setup processes.

Google Apps Script offers a simpler alternative. With 13 lines of code, this solution works directly in Google Sheets without additional tools or subscriptions.

The Magic Behind the Script

The solution leverages Google Apps Script (Google's built-in automation tool) to scan a Drive folder, grab every CSV file, and automatically create separate sheets for each one in your main spreadsheet.

Here's what the core function looks like:

function combineCSV() {
    const folderId = 'YOUR_FOLDER_ID_HERE'; // Replace with the folder ID where your CSVs are stored
    const folder = DriveApp.getFolderById(folderId);
    const files = folder.getFilesByType(MimeType.CSV);
    const ss = SpreadsheetApp.getActiveSpreadsheet();

    while (files.hasNext()) {
        const file = files.next();
        const csvData = Utilities.parseCsv(file.getBlob().getDataAsString());
        const sheet = ss.insertSheet(file.getName());
        sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
    }
}

That's it. Thirteen lines that replace hours of manual work.

Why This Works So Well

  • It's Simple: Copy one folder ID, paste some code, click a button. Done.

  • It Scales: Whether you have 3 files or 30 files, the process is identical.

  • It's Reliable: No human error from copy-paste mistakes or missed data.

  • It's Free: Uses tools you already have access to.

  • It's Flexible: Works with any CSV structure, any number of files.

The Process (High Level)

  1. Upload CSV files to a Google Drive folder

  2. Copy the folder ID from the URL

  3. Paste the script into Google Apps Script

  4. Add a button to trigger the script

  5. Click to combine all files automatically

The setup takes about 5 minutes. After that, combining any number of CSV files becomes a one-click operation.

Automate Your Business, One Tool at a Time

Effective business automation starts with identifying one painful, repetitive task and solving it systematically. CSV combining, report generation, or data cleanup – the specific task matters less than establishing the automation mindset.

Ready to eliminate manual work that computers handle better?

I help business owners and teams identify, build, and implement practical automation solutions.

Have a problem or time-sink you’d like automated? Reply directly to this email with your most time-consuming manual task.

P.S. - I read every reply. Feel free to reach out directly.

NEXT STEPS

Whenever you’re ready, here’s how I can help:

  1. Business tech stack (FREE)
    My recommendations for software and tools I use to create content and run my online business.

  2. Sponsor Got Sheet
    Got Sheet teaches business operators, teachers and entrepreneurs how to get good at spreadsheets. Interested in sponsoring an issue or a series of Got Sheet newsletters? Reach out to get more information.

  3. Personal budget tool
    As a Got Sheet subscriber, I want you to have a 50% discount on the personal finance system I update every year.

  4. YouTube

    If you aren’t subscribed yet, come on over to my YouTube channel where I make all my spreadsheet, coding and productivity tutorials

HAPPY SPREADSHEETING!

Enjoyed this issue?
Subscribe below or Leave a testimonial

Cheers, Eamonn
Connect on LinkedIn, YouTube & Twitter.

Reply

or to participate.