A macro imports multiple CSV files into Excel by looping through every file in a folder, opening each one, copying its data and pasting it onto a single sheet or onto separate tabs. The most practical way is to record or paste a short VBA routine into the workbook, point it at a folder, and run it once — every CSV is then consolidated in seconds instead of dozens of manual copy-and-paste operations. Before you start you need the CSV files in one folder, a workbook saved as .xlsm (macro-enabled), and the Developer tab visible, because macros are disabled in ordinary .xlsx files.

What You'll Need

  • A folder containing the CSV files you want to import, ideally with identical column structure.
  • Excel on Windows or Mac with macros enabled by your organisation. The VBA editor works on both, though menu wording differs slightly.
  • The workbook saved as an Excel Macro-Enabled Workbook (.xlsm). Standard .xlsx files cannot store macros.
  • The Developer tab switched on (File > Options > Customize Ribbon, or Excel > Preferences on Mac). Menu labels can differ slightly by version and region.
  • Trust access to the VBA project object model only if your IT policy allows it — you usually do not need it for simple file imports.

Step-by-Step

  1. Collect and check the CSVs. Put every file in one folder and delete any you do not want. Open two or three and confirm they share the same header row and column order. A mismatched file will paste its values into the wrong columns later, so fixing it now saves confusion.
  2. Create a new workbook and save it as .xlsm. Go to File > Save As, choose Excel Macro-Enabled Workbook from the file type list, and give it a name. Do this before writing any code, otherwise Excel will warn you that macros cannot be saved.
  3. Open the VBA editor. Press Alt+F11 on Windows, or Option+F11 on Mac. In the editor, use Insert > Module to add a blank code module. The module is where your routine will live.
  4. Paste a folder-loop routine. A reliable structure is: declare variables, ask the user to pick a folder, loop through every *.csv file with the Dir function, open each file, copy its used range, paste it below the last used row on a destination sheet, close the CSV without saving, then call Dir again without arguments. Use Application.ScreenUpdating = False at the start and set it back to True at the end so the screen does not flicker on every file. Turn off Application.DisplayAlerts while closing files and restore it afterwards.
  5. Point the macro at your destination. Replace the placeholder sheet name in the paste step with the real name of your summary sheet. If you want each file on its own tab instead of stacked rows, paste into a newly added worksheet named after the file rather than the same sheet.
  6. Handle the header row. If the first CSV should bring its header and the rest should not, skip row 1 for every file after the first. A simple counter variable works: paste the full range when the counter is 1, and paste offset by one row for everything after.
  7. Run the macro. Close the editor, then use Developer > Macros (Alt+F8 on Windows), select your routine and click Run. A folder-picker dialog appears if you included one; choose your CSV folder.
  8. Check the result. Scroll to the bottom of the destination sheet and confirm the last file's data is present. Compare row counts against the files in the folder. Delete any blank rows left behind by an empty source range.
  9. Save and reuse. Save the .xlsm workbook. Next month, drop new CSVs into the folder and run the same macro again. If your IT team blocks macros, publish it through a trusted location rather than lowering security settings broadly.

Common Mistakes

The most frequent failure is saving as .xlsx, which silently strips the macro; the workbook then opens with the code gone. Another common issue is forgetting to reset ScreenUpdating and DisplayAlerts when the macro errors partway through, leaving Excel in a strange state until it restarts. Pasting without clearing old data causes duplicates on every run, so either clear the destination sheet at the start or paste to a fresh sheet. Many people also leave Dir loops hanging by forgetting the bare Dir call at the end, which causes an endless loop. Finally, mismatched delimiters break imports in regions where the list separator is a semicolon instead of a comma — check how Excel is parsing the file before blaming the code.

Tips

Name your range or use a dynamic last-row calculation instead of hard-coding row numbers, so the macro keeps working as data grows. Add a column with the source file name during import — it makes consolidating months of exports far easier later. Test on three files before running on three hundred, and keep a backup copy of the workbook before the first live run. If your CSVs use a non-standard encoding, import with a query rather than opening the file directly, and note that Power Query (Data > Get Data) can combine a whole folder without any VBA at all — worth using if macros are restricted.

Troubleshooting

Nothing happens when you run it: macros may be disabled. Check the yellow security bar and enable content only for files you trust. The folder picker points nowhere: verify the path has no trailing space and that the network drive is mapped. Data lands in the wrong columns: the CSVs use a different delimiter; open one via Data > From Text/CSV to confirm. Run-time error on Close: a file is already open in Excel; close it first. The macro is slow: turn off screen updating and calculation during the loop, then recalculate once at the end. Duplicate rows appear: the destination is not being cleared between runs — add a clear step or delete old data manually.

Frequently Asked Questions

Can I import every CSV on its own worksheet?

Yes. Add a new sheet inside the loop and paste the file's data there, naming the sheet after the file.

Does this work on Mac?

VBA runs on Excel for Mac, but some Windows-only dialogs differ, so use a simpler folder path variable if the picker misbehaves.

What if my organisation blocks macros?

Use Data > Get Data > From Folder in Power Query, which combines files without any code.

Will it overwrite existing data?

Only if you tell it to. By default it pastes below the last used row, so clear the sheet first if you want a fresh import.

Can it skip files that are still downloading?

Add a check for file size or catch the open error, then log the skipped file name so you can retry later.

Do I need to keep the CSVs after importing?

No — once the data is in the workbook you can archive or delete the originals, but keep a copy until you have verified the import.