VBA & Macro Problems

How to Export Excel Rows to Separate Customer Files Using VBA

Olivia MillerOlivia Miller Oct 23, 2026 870 views

Question details

The user wants to export transaction records from a master Excel sheet into individual files or PDFs for each unique customer using a VBA macro.

Export Excel Rows to Separate Customer Files Using VBA
Product
Excel
Device & OS
not provided
Scenario
Automating the separation and export of customer-specific data from a large dataset.
Observed behavior
Data needs to be filtered by unique customers, formatted with headings, and saved as separate workbooks or PDFs automatically.
Before you start

Always test VBA macros on a backup copy of your original workbook to prevent accidental data loss. Create a dedicated folder on your computer to store the generated output files.

Solution 1Recommended

Use a VBA Macro to Filter and Export Customer Data

Run a custom VBA macro to automatically split your dataset by customer name and save each subset as a new workbook or PDF.

This macro identifies unique customers in your dataset, applies a filter for each, and copies the visible rows to a temporary sheet. It then exports that sheet and cleans up by deleting the temporary sheet.

Ensure your customer names do not contain invalid file characters (like slashes or asterisks).

1
Prepare your data

Ensure your dataset has clear column headers and no blank rows. Identify the column containing the customer names.

2
Open the VBA Editor

Press ALT + F11 to open the Visual Basic for Applications (VBA) editor in Excel.

3
Insert a new module

Click 'Insert' from the top menu and select 'Module' to create a blank script window.

4
Write the macro script

Write a VBA script that loops through unique customer names, filters the dataset, copies visible rows to a new worksheet, and uses ActiveWorkbook.SaveAs or ActiveSheet.ExportAsFixedFormat to save the file.

5
Run the macro

Press F5 or click the 'Run' button. Check your designated output folder to verify the separate files have been created.

Use a VBA Macro to Filter and Export Customer Data
Invalid File Names: If the macro fails to save a file, check if the customer name contains illegal characters for filenames, such as \, /, :, *, ?, ", <, >, or |.
Powerful VBA Support in WPS

Automate Data Exports with WPS Spreadsheet

WPS Spreadsheet provides excellent support for VBA macros, allowing you to easily automate repetitive tasks like splitting datasets and exporting customer records to separate files or PDFs.

  1. 1. Enable Developer Tools: Open WPS Spreadsheet, go to the Options menu, and enable the Developer tab to access Macro features.
  2. 2. Open VBA Editor: Click on 'Macros' or press ALT + F11 to launch the VBA Editor.
  3. 3. Paste and Run Code: Insert a new module, paste your customer export VBA code, and click Run to automatically generate the individual files.
Full compatibility with Microsoft Excel (.xlsx, .xlsm) formats.Robust VBA and macro support to automate complex data tasks.Lightweight application that processes large datasets quickly.
microsoft office alternative - wps office

Frequently Asked Questions

Why am I getting an error when saving the individual Excel files?

This usually happens if the customer name contains characters that Windows does not allow in file names (like slashes or question marks), or if the specified output folder path does not exist in your VBA code.

Can I export the customer data as PDF instead of Excel workbooks?

Yes. In your VBA code, you can use the ExportAsFixedFormat method with the type set to xlTypePDF instead of using SaveAs, which will save the temporary worksheet directly as a PDF document.

How do I extract unique customer names in VBA?

You can extract unique customer names by copying the customer column to a hidden sheet and using the RemoveDuplicates method, or by using a Collection or Dictionary object in VBA to store only unique values as you loop through the rows.

Is there a way to split data into separate files without VBA?

Without VBA, you would have to manually filter the data by customer, copy the results, paste them into a new workbook, and save it. For large datasets, VBA or Power Query combined with third-party automation tools is highly recommended to streamline the process.