VBA & Macro Problems

How to Split Excel Data into Separate Sheets by First Three Characters in WPS Office

Steven ParkerSteven Parker Nov 13, 2026 869 views

Question details

The user needs to group rows in a worksheet by the first three characters of a text column and automatically copy each matching group to a separate worksheet.

How to Split Excel Data into Separate Sheets by First Three Characters in WPS Office
Product
WPS Spreadsheets
Device & OS
not provided
Scenario
A source column contains text values that must be grouped according to their first three characters, with each group distributed to its own sheet.
Observed behavior
Matching records remain in the source sheet and formulas cannot write results to other worksheets, so the task requires either a VBA macro or a manual filter-and-copy workflow.
Before you start

Before running the macro, confirm the source sheet name and the source column match the code, and save the workbook as a macro-enabled file (.xlsm) so the VBA project is retained.

Solution 1Recommended

Use a VBA Macro to Automatically Create a Sheet for Each Prefix and Copy Matching Rows

Use this solution when you need the source rows automatically distributed to multiple worksheets without manual filtering and copying.

VBA is required when the result must be written to multiple worksheets automatically because Excel formulas only return values in the cells that contain them. The macro reads the source column, extracts each value's first three characters with Left, creates or finds a matching worksheet, and copies the record to that sheet.

1
Open the VBA editor

In WPS Spreadsheets, press Alt+F11, or click the Developer tab and then click View Code.

2
Insert a module

In the VBA editor, click Insert > Module to create a new code module.

3
Paste the split-by-prefix macro

Paste a VBA macro that loops through column A from A2 to the last used row, extracts Left(cell.Value, 3), creates a worksheet named with that prefix if it does not exist, and copies the entire row to the matching worksheet.

4
Adjust the source sheet and column

Change the source worksheet name and column reference in the code to match your workbook, for example Sheet1 and column A.

5
Run the macro and save as macro-enabled

Place the cursor inside the macro and press F5 or click Run > Run Sub/UserForm, then save the workbook as a macro-enabled file (.xlsm).

Use a VBA Macro to Automatically Create a Sheet for Each Prefix and Copy Matching Rows
Macro-enabled save required: Save the workbook as .xlsm after adding the macro; .xlsx files cannot retain VBA code.
WPS Spreadsheets macro guide

Split Excel Data into Separate Sheets by First Three Characters with WPS Office

WPS Spreadsheets can run the VBA macro directly, automatically creating a worksheet for each three-character prefix and copying matching rows. It keeps your Excel-compatible workflow intact and supports both .xlsx and .xlsm files.

  1. 1. Open your workbook: Open the target workbook in WPS Spreadsheets.
  2. 2. Open the macro editor: Press Alt+F11 or click Developer > View Code, then insert a new module.
  3. 3. Add the split-by-prefix macro: Paste the VBA macro and change the source sheet name and source column to match your data.
  4. 4. Run the macro: Press F5 or click Run > Run Sub/UserForm to create and populate a worksheet for each three-character prefix.
  5. 5. Save as macro-enabled workbook: Save the file as .xlsm so the macro is stored and can be reused.
Automatically creates a sheet for each three-character prefix and copies matching rows.Maintains full Microsoft Excel .xlsx and .xlsm format compatibility.Free WPS Office includes spreadsheet macros and a familiar Alt+F11 VBA workflow.Lightweight installation and easy migration from Excel without retraining.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use this method to group by the first 4 or 5 characters instead of 3?

Yes. In the VBA macro, change Left(cell.Value, 3) to Left(cell.Value, 4) or the number you need, and replace the helper-column formula =LEFT(A2,3) with =LEFT(A2,4).

Why does the macro fail with an invalid sheet name error?

Usually one of the first three characters is not allowed in a worksheet name, such as \, /, *, ?, :, [ or ]. Clean or replace those characters before naming the destination sheet.

Do I have to save the workbook as a macro-enabled file?

Yes. Save it as .xlsm in WPS Spreadsheets or Microsoft Excel, otherwise the VBA macro will not be stored when you close the file.

Can I split the data without enabling macros?

Yes. Add a helper column with =LEFT(A2,3), turn on AutoFilter, filter each prefix, and copy the visible rows to separate sheets manually.