How to Fix Excel VBA ComboBox Change Event Errors with Numeric Values
Question details
The user needs to fix an error occurring in an Excel VBA ComboBox Change event when processing numeric data.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Loading data from a worksheet column (e.g., column J) into a Dictionary to repopulate a ComboBox and apply a worksheet filter.
- Observed behavior
- The VBA macro fails and throws an error because string-specific functions, such as LCase, are being applied directly to numeric values.
Before modifying your VBA code, ensure you have saved a backup copy of your macro-enabled workbook. Press Alt + F11 to open the VBA Editor and locate the specific UserForm or Sheet containing the problematic ComboBox code.
Remove String Functions from Numeric Variables
Prevent type mismatch errors by ensuring string functions are only applied to text strings, or by explicitly converting numbers to strings before processing.
VBA strictly separates data types. String manipulation functions like LCase or UCase expect text data. When they encounter pure numeric values without explicit conversion, VBA generates a runtime error.
To resolve this, you must treat numeric values as numbers during the dictionary loading phase or convert them safely to strings.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor. Find the code block for your ComboBox's Change event or the initialization subroutine loading the values.
Search the subroutine for string-specific functions such as LCase, UCase, or Trim that are being applied to the cell values retrieved from the worksheet column.
If text normalization is not required for numbers, remove the LCase function. Alternatively, convert the cell value to a string first by wrapping it in CStr(), for example: LCase(CStr(cell.Value)).
Ensure your Scripting.Dictionary assigns the correctly formatted variable as its key. Repopulate your ComboBox using the dictionary keys and apply your worksheet filter.

Debug and Run VBA Macros Seamlessly in WPS Spreadsheet
WPS Office provides excellent compatibility with Microsoft Excel VBA macros. You can easily edit, debug, and run your ComboBox controls and user forms within the WPS Spreadsheet environment.
- 1. Open your Workbook: Launch WPS Spreadsheet and open your macro-enabled workbook (.xlsm).
- 2. Access the VBA Editor: Navigate to the 'Developer' tab on the ribbon and click the 'Visual Basic' icon to open the integrated VBA Editor.
- 3. Edit and Debug: Locate your ComboBox code, apply the correct data type handling for numeric values, and use the debugging tools to run the macro directly.

Frequently Asked Questions
Why does the LCase function cause an error with numbers in VBA?
The LCase function is designed strictly for string data types. Passing a purely numeric value or a Null cell value to it without explicit conversion causes a 'Type Mismatch' error (Runtime Error 13) in VBA.
How do I populate a ComboBox with unique values using a Dictionary?
You can use the Scripting.Dictionary object in VBA to loop through a range. Check if the value exists as a dictionary key using the .Exists method; if it doesn't, add it. Finally, assign the dictionary's .Keys array to the ComboBox's .List property.
How can I safely convert a numeric cell value to text in VBA?
Use the CStr() function to convert a number to a string. For example, CStr(Range("J2").Value) ensures the numerical value is treated as text before you apply text-manipulation functions like LCase or add it to a ComboBox list.




