When a CSV file grows to hundreds of thousands of rows, it becomes slow to open in Excel, hard to email, and risky to edit. Splitting it into smaller, more manageable files lets you work with each chunk quickly, share it without hitting attachment limits, and keep your main data safe. This guide shows you three practical methods—using Excel’s Power Query, a simple VBA macro, and a free command-line tool—so you can choose the one that fits your comfort level. No special software is required beyond what you likely already have.
What You’ll Need
- The large CSV file you want to split (make a backup copy first).
- Microsoft Excel (2016 or later) if you use the Power Query or VBA method. Excel for Microsoft 365 on Windows is assumed; Mac steps are noted where they differ.
- Optional: A command-line tool like
csvsplit(free, open-source) if you prefer a scripted approach.
Step-by-Step
Method 1: Using Excel Power Query (No Coding)
- Open a blank workbook in Excel. Go to the Data tab and click From Text/CSV (in Excel for Microsoft 365, it’s under Get Data). On Mac, go to Data > Get Data > From Text/CSV.
- Select your CSV file and click Import. The Power Query editor opens, showing a preview of your data. Check that the columns look correct.
- Add an index column to help split the data. In the Power Query editor, go to Add Column > Index Column > From 1. This adds a column with numbers 1, 2, 3, etc.
- Create a grouping column to divide the data into chunks. For example, if you want files of 10,000 rows each, add a custom column. Go to Add Column > Custom Column. In the formula box, enter:
Number.RoundUp([Index]/10000). This assigns a group number (1, 2, 3…) to every 10,000 rows. Adjust the 10000 to your desired chunk size. - Remove the Index column (optional) by right-clicking its header and selecting Remove. Keep the custom column; it will be your split key.
- Close and load the query by clicking Close & Load on the Home tab. This loads the data into a new worksheet in Excel.
- Filter and copy each chunk. In the loaded worksheet, click the filter arrow on the custom column header (e.g., “Custom”). Uncheck all boxes except the first group (e.g., 1). Copy the visible rows (excluding the header) and paste them into a new workbook. Save that workbook as a CSV file. Repeat for each group number.
- Alternative: Use a PivotTable to split automatically. If you prefer not to copy manually, you can create a PivotTable with the custom column as a filter, but the copy-paste method is simpler for most users.
Method 2: Using a VBA Macro (Automated)
- Open the CSV file in Excel. Press Alt+F11 to open the VBA editor (Mac: Fn+Option+F11).
- Insert a new module: In the VBA editor, go to Insert > Module.
- Paste the following code into the module:
Sub SplitCSV() ' Splits the active sheet into multiple CSV files Dim ws As Worksheet Dim rng As Range Dim lastRow As Long Dim chunkSize As Long Dim i As Long Dim startRow As Long Dim endRow As Long Dim outputPath As String Dim fileName As String Dim newWb As Workbook ' Set chunk size (rows per file) chunkSize = 10000 ' Get active sheet and last row Set ws = ActiveSheet lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row ' Ask for output folder outputPath = InputBox("Enter the full path of the output folder (e.g., C:\CSV_Splits)") If outputPath = "" Then Exit Sub ' Loop through chunks For i = 1 To lastRow Step chunkSize startRow = i endRow = Application.WorksheetFunction.Min(i + chunkSize - 1, lastRow) ' Copy the chunk to a new workbook Set newWb = Workbooks.Add ws.Rows(startRow & ":" & endRow).Copy newWb.Sheets(1).Range("A1").PasteSpecial xlPasteValues ' Save as CSV fileName = outputPath & "\chunk_" & Format(startRow, "000000") & ".csv" newWb.SaveAs fileName, FileFormat:=xlCSV newWb.Close SaveChanges:=False Next i MsgBox "Done! Files saved to " & outputPath End SubNote: This macro copies values only, not formatting. Save a copy of your workbook before running any macro, as macros cannot be undone with Ctrl+Z.
- Run the macro by pressing F5 while in the VBA editor (or close the editor and press Alt+F8, select SplitCSV, and click Run). Enter the output folder path when prompted.
Method 3: Using a Command-Line Tool
- Download a free CSV splitter like
csvsplitfrom a trusted source (e.g., GitHub). Ensure you have a command-line environment (Windows Command Prompt, PowerShell, or Terminal on Mac). - Navigate to the folder containing the tool and your CSV file. For example, in Command Prompt:
cd C:\Tools - Run the command to split the file. For
csvsplit, the typical syntax is:csvsplit -i large.csv -o output_folder -n 10000. This splitslarge.csvinto files of 10,000 rows each inoutput_folder. Check the tool’s documentation for exact flags. - Verify the output by opening a few of the generated CSV files to ensure they contain the expected rows and headers.
Common Mistakes
- Not preserving the header row – Every split file should include the original header row so it can be used independently. The VBA macro above copies the header only in the first chunk; you may need to adjust it to include headers in every chunk.
- Using a fixed split that breaks rows – If your CSV has multi-line fields (quoted text with line breaks), a simple row-count split will corrupt data. Always ensure your splitter respects quoted fields.
- Overwriting original data – Always work on a copy. Splitting in place can lead to accidental data loss.
- Ignoring file size limits – Some tools split by rows, but if your CSV has very long fields, a row-based split may still produce large files. Consider splitting by size as well.
Tips
- Choose a chunk size based on your needs – For Excel, 10,000–50,000 rows per file is a good range. For email attachments, keep files under 10 MB.
- Test with a small sample first – Before splitting the entire file, test your method on a copy with just a few thousand rows to verify the output.
- Use consistent naming – Name output files like
data_part_001.csvto keep them in order. - If you use Excel’s Power Query, consider saving the query – You can reuse it if your CSV gets updated, by refreshing the query.
Troubleshooting
- Power Query doesn’t show the index column – Make sure you are in the Power Query editor, not just the preview. Click Transform Data after importing to open the editor.
- The VBA macro errors with “Subscript out of range” – This usually means the output folder path doesn’t exist. Create the folder first, or modify the code to create it using
MkDir. - The split files have missing rows – Check if your CSV contains blank lines or special characters. Some tools may misinterpret them. Try using a different method, or pre-process the file to remove blank lines.
- Excel freezes when opening the large file – If the file is too large to open even once, use the command-line tool or a text editor like Notepad++ to split it, or use a dedicated CSV splitter that doesn’t require loading the whole file.
Frequently Asked Questions
- Can I split a CSV file without Excel? – Yes, you can use a command-line tool or a text editor, but for large files, a dedicated splitter is more reliable.
- Will splitting affect the data quality? – No, if done correctly, each split file contains a subset of the original rows with the same column structure. Ensure you include headers and respect quoted fields.
- How do I decide the chunk size? – Consider the tool you’ll use to open the files (Excel handles ~1 million rows max) and your email attachment limit. A common choice is 10,000–50,000 rows.
- What if my CSV has a header row? – Most methods allow you to include headers in every split file. In the VBA macro, you can modify the copy range to include row 1 in each chunk.
- Can I split by column instead of rows? – Yes, but that’s less common. You can use Power Query to select specific columns and export them as separate CSVs, or use a script to filter by a column value.
- Is there a way to split a CSV online? – Yes, there are online tools, but be cautious with sensitive data. For privacy, use offline methods.
Related
- Select a Cell Shortcut: Top Excel Keyboard Shortcuts
- How Much Coding for Data Entry? A Practical Guide
- Google Sheets VLOOKUP: How to Use It Correctly
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How to Split Cells in Excel (Text to Columns & More)To split cells in Excel means to divide the contents of one cell into two or more separate…
- How to Archive Emails in Outlook on a MacBook: StepsTo archive an email in Outlook on a MacBook, select the message and choose Archive on the Outlook…
- What Is an Enum in a Database? Definition & UseAn enum (short for “enumeration”) in a database is a data type that restricts a column to a…
- Excel Cell Phone Accessories in Clementi: What to KnowIf you mean a shop called Excel that sells cell phone accessories in Clementi, I can’t reliably confirm…
- Content Calendar Template Excel: Create and Use OneYes. A useful Excel content calendar template is a workbook with one row per planned post and columns…
- Add Page Numbers in Word on Mac: Step-by-Step GuideTo add page numbers in Word on a Mac, open the Insert tab, choose Page Number, select where…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.