How to Replace Excel Group Names with 'Other' When Count is Below 10
Question details
The user needs to consolidate low-frequency categorical data by renaming any group that appears less than 10 times in a column to 'Other'.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Cleaning and organizing datasets where minor, infrequent group names (like specific colors) need to be combined into a general 'Other' category for easier analysis.
- Observed behavior
- The column currently contains multiple individual group names, and manual replacement is inefficient for large datasets.
Ensure your target data begins in cell D2 of the active worksheet and verify there are no blank cells within the column, as this may interrupt the data range selection.
Use a VBA Macro to Replace Low-Frequency Group Names
Execute a custom VBA script to quickly evaluate the column array in memory and overwrite groups appearing fewer than 10 times with 'Other'.
Using VBA is the most efficient method for this task because it processes the data array in the background (disabling screen updating) and overwrites the original cells instantly.
Press Alt + F11 on your keyboard to launch the Microsoft Visual Basic for Applications window.
Click 'Insert' in the top menu and select 'Module' to create a blank workspace for your code.
Copy and paste the following code into the module window: Sub Set2Other() Dim rng As Range Dim v As Variant Dim i As Long Set rng = Range(Range("D2"), Range("D2").End(xlDown)) v = rng.Value For i = 1 To UBound(v) If Application.CountIf(rng, v(i, 1)) < 10 Then v(i, 1) = "Other" End If Next i Application.ScreenUpdating = False rng.Value = v Application.ScreenUpdating = True End Sub
Press F5 or click the 'Run' button (the green triangle) in the toolbar. The data in column D will be automatically updated.

Use a Helper Column with the COUNTIF Function
If you prefer to avoid VBA, you can combine the IF and COUNTIF functions to dynamically generate the updated names in an adjacent column.
Easily Manage Macros and Formulas with WPS Spreadsheet
WPS Office offers full support for complex data processing, including advanced formulas and VBA macros, allowing you to quickly clean and consolidate your data without hassle.
- 1. Open your file in WPS Spreadsheet: Launch WPS Office and open your workbook containing the categorized data.
- 2. Access the Developer Tools: Navigate to the 'Developer' tab on the ribbon to access the VBA Editor and macro settings.
- 3. Execute the Macro or Formula: Insert the VBA code or helper column formulas just as you would in Microsoft Excel to instantly update your group categories.

Frequently Asked Questions
How can I change the minimum count threshold from 10 to another number?
In the VBA code, locate the line `If Application.CountIf(rng, v(i, 1)) < 10 Then` and change the number 10 to your desired threshold (e.g., 5 or 20). If using the formula method, change the `<10` in the formula accordingly.
Why is the macro not updating all of my data?
The provided VBA macro uses `End(xlDown)` to define the range. If there are blank cells within your data column, the macro will stop at the first blank cell. Ensure your dataset is contiguous or manually define the range in the script.
Can I apply this macro to multiple columns at once?
The current script is designed for a single specific column (D). To apply it to multiple columns, you would need to modify the VBA script to loop through each column or adjust the range definition to encompass a multi-column array.
How do I save a workbook that contains VBA macros?
To preserve your VBA code, you must save your file as an Excel Macro-Enabled Workbook (.xlsm). Go to File > Save As, and select 'Excel Macro-Enabled Workbook' from the file format dropdown.




