How to Export Excel Rows to Separate Customer Files Using VBA
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.

- 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.
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.
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).
Ensure your dataset has clear column headers and no blank rows. Identify the column containing the customer names.
Press ALT + F11 to open the Visual Basic for Applications (VBA) editor in Excel.
Click 'Insert' from the top menu and select 'Module' to create a blank script window.
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.
Press F5 or click the 'Run' button. Check your designated output folder to verify the separate files have been created.

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. Enable Developer Tools: Open WPS Spreadsheet, go to the Options menu, and enable the Developer tab to access Macro features.
- 2. Open VBA Editor: Click on 'Macros' or press ALT + F11 to launch the VBA Editor.
- 3. Paste and Run Code: Insert a new module, paste your customer export VBA code, and click Run to automatically generate the individual files.

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.




