Excel VBA UserForm Invalid Property Value: Fix Guide
In this article
The "invalid property value" error in an Excel VBA UserForm means the code is trying to assign a value that the property cannot accept at that moment. The fastest fix is to open the form in the VBA editor, press F8 to step through the code line by line, and note the exact line where the error triggers. That line is almost always assigning to a property such as Value, Text, ListIndex, or BackColor, and the value on the right side of the equals sign does not match what the control expects. Correct the value or guard the assignment with a check, and the error goes away.
What You'll Need
- Excel with the Developer tab enabled (File > Options > Customize Ribbon > check Developer).
- The workbook containing the UserForm, opened with macros enabled.
- Access to the VBA editor (Alt+F11).
- A basic understanding of which control is being loaded or updated when the error appears.
Step-by-Step
- Reproduce the error deliberately. Open the UserForm the same way a user would (a button on the sheet, a shortcut, or the macro dialog). Note exactly when the message appears: on load, after typing in a text box, when clicking a button, or when closing. The timing narrows down which event procedure contains the bad assignment.
- Open the VBA editor. Press Alt+F11. In the Project Explorer, expand your workbook, then Forms, and double-click the UserForm to bring up its code window. If the error happens on load, look at the UserForm_Initialize procedure. If it happens when a button is clicked, look at that button's Click procedure.
- Turn on break-on-all-errors. In the VBA editor menu, choose Tools > Options > General tab, and select Break on All Errors. This forces the debugger to stop on the offending line instead of silently continuing or showing a generic message. Labels in the Options dialog can differ slightly by Excel version and language, so look for the error-trapping section if the wording is not identical.
- Step through with F8. Place the cursor at the top of the suspect procedure and press F8 repeatedly. Each press runs one line. When the line that assigns a property highlights and the error appears, you have found the culprit. Typical examples are
TextBox1.Value = Range("A1").Value,ComboBox1.ListIndex = 5, orOptionButton1.Value = True. - Check the right-hand side first. The value being assigned is usually the problem. A text box assigned a number is fine, but a text box assigned an error value such as
#N/Aor an empty Variant can fail. A ComboBox ListIndex set to a number larger than the list count fails. A BackColor or ForeColor set to a number outside the valid range fails. Inspect the value in the Immediate Window (Ctrl+G) by typing?Range("A1").Valueor?ComboBox1.ListCountbefore the assignment runs. - Check the left-hand side control name. A common cause is a typo or a renamed control. If you renamed TextBox1 to txtName on the form but the code still refers to TextBox1, VBA may raise an error at compile time or at run time depending on the context. In the Properties window (F4), confirm the Name property of the control matches the code exactly, including case.
- Guard assignments with validation. Wrap the assignment in a check. For example, before setting a ListIndex, test
If ComboBox1.ListCount > 0 Then ComboBox1.ListIndex = 0. Before assigning a cell value to a control, testIf Not IsError(Range("A1").Value) Then TextBox1.Value = Range("A1").Value. This prevents the error from recurring when data changes. - Check for read-only or unsupported properties. Some properties cannot be set at run time or are only valid in certain states. For example, setting the Value of a ComboBox to a string that is not in its list raises an error unless MatchRequired is False. Setting the Text property of a control that does not have focus can also fail. Use the correct property for the control type and state.
- Compile and test. In the VBA editor, choose Debug > Compile VBAProject. Fix any compile errors it reports. Then close the form, reopen it, and repeat the action that caused the error. If the error is gone, save the workbook as a macro-enabled file (.xlsm).
Common Mistakes
- Ignoring the line number. The error dialog often does not show which line failed. Stepping with F8 is the reliable way to find it.
- Assuming the control is the problem. Most invalid property value errors come from the value being assigned, not the control itself.
- Forgetting that empty cells return Empty, not blank text. Assigning an Empty Variant to a control that expects a string can fail. Convert with CStr or check with IsEmpty first.
- Setting ListIndex before the list is populated. If the list is filled in Initialize but the assignment runs before that, the index is out of range.
- Renaming controls without updating code. Use Find and Replace carefully, or let the Properties window update the name and then fix references.
Tips
- Add
On Error GoTohandlers only after you have found the failing line, so you do not mask the real cause. - Use meaningful control names (txtName, cboState, btnSave) to make code easier to read and less error-prone.
- Keep Initialize procedures short and move data loading into separate routines you can test independently.
- Use the Locals window (View > Locals) while stepping to see the current values of all variables and controls.
- Test the form with empty data, error values, and very long text to catch edge cases early.
Troubleshooting
If stepping with F8 does not reveal the line, the error may be happening in a different procedure than you expect. Check the UserForm's Initialize, Activate, and Click events, and any class modules the form uses. If the error appears only for some users, their regional settings may format numbers or dates differently; convert values explicitly with CStr, CLng, or CDate before assigning. If the form fails only after data is refreshed, check that the refresh routine does not clear a list that a control still references. If the error persists after all checks, export the form (File > Export File in the VBA editor), import it into a clean workbook, and test there to rule out corruption. Finally, ensure the workbook is not in a protected view or read-only mode, which can block property changes.
Frequently Asked Questions
What does "invalid property value" mean in a VBA UserForm?
It means the code tried to set a control property to a value that property does not accept, such as a ListIndex beyond the list count or a color outside the allowed range.
Why does the error only happen sometimes?
The assigned value depends on data or user input. When the data is valid the assignment succeeds; when it is empty, an error value, or out of range, it fails.
Can I ignore the error with On Error Resume Next?
You can, but it hides the cause and can leave controls in an inconsistent state. Fix the assignment instead, or use a targeted check before assigning.
How do I find which line causes the error?
Set Break on All Errors in Tools > Options, then step through the procedure with F8 until the failing line highlights.
Does this error affect the saved workbook?
No. It is a run-time error in the form's code. Once the code is corrected and the workbook saved as .xlsm, the form behaves normally.