VBA & Macro Problems

Fix Backspace in a Word VBA UserForm Text Box

Nimra MalikNimra Malik Nov 22, 2026 869 views

Question details

The user needs to make Backspace work in a Word VBA UserForm text box while preserving leading-zero formatting.

Fix Backspace in a Word VBA UserForm Text Box
Product
Microsoft Word VBA UserForm
Device & OS
not provided
Scenario
A UserForm text box formats its value with leading zeros as the user edits a three-character entry.
Observed behavior
The Change event immediately reformats the value after each keystroke, making Backspace appear not to work.
Before you start

Open the document in Word, press Alt+F11, and locate the affected UserForm and text box in the VBA editor. Check the text box's Change event for code that rewrites its value.

Solution 1Recommended

Format the text box value when the user leaves the field

Move the formatting logic to the Exit event so users can delete and edit characters without immediate reformatting.

1
Remove immediate formatting

In the VBA editor, open the UserForm's code and remove the value-formatting code from Text11_Change. Replace Text11 in the following examples with your text box's actual name.

2
Add an Exit event

Select the text box in the UserForm designer, open its code window, and choose Exit from the event list. Add this procedure: Private Sub Text11_Exit(ByVal Cancel As MSForms.ReturnBoolean) If IsNumeric(Me.Text11.Value) Then Me.Text11.Value = Format(Me.Text11.Value, "00#") Else Me.Text11.Value = "N/A" End If End Sub

3
Optionally restrict typed input

Add a Text11_KeyPress event to allow digits and Backspace while blocking other typed characters: Private Sub Text11_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then KeyAscii = 0 End If End Sub

4
Test the form

Run the UserForm, type a number in Text11, use Backspace, and then move focus to another control. The value should be formatted only after you leave the field.

Format the text box value when the user leaves the field
Formatting and validation: The format "00#" pads numeric values to at least three digits; it does not limit longer values. The Exit event replaces empty or nonnumeric entries with N/A. KeyPress filtering does not validate pasted text, so retain the Exit check.
Free Microsoft Office alternative

Edit Word documents with WPS Office

WPS Office is a free, lightweight alternative for editing Word documents with a familiar interface and a straightforward move from Microsoft Office. It does not repair Word's VBA UserForm events; macro support and compatibility may vary.

Edit documents in a familiar word-processing interfaceCompatible with Microsoft Word DOC and DOCX formatsWork with document content without relying on the affected UserFormFree, lightweight office suite for everyday tasks
microsoft office alternative - wps office

Frequently Asked Questions

Why does Backspace seem to do nothing in my UserForm?

A Change event can rewrite the text box after every keystroke. If it immediately adds leading zeros again, a deletion can appear to have no effect.

When does the text box Exit event run?

The Exit event normally runs when focus moves away from the text box to another control. Put the formatting code in Text11_Exit so editing can finish first.

Do I need a Frame Exit event too?

Not necessarily. First test the text box's Exit event by moving focus to another control. The reported case worked without a separate Frame1_Exit procedure.

Does the format 00# restrict entries to three digits?

No. Format(value, "00#") adds leading zeros to make a numeric value at least three digits, but it does not truncate longer numbers. Add separate validation if you need a maximum.

Will the KeyPress event block pasted nonnumeric text?

Not reliably. KeyPress filters typed characters, so use the Exit event's IsNumeric check to validate the final value as well.