VBA & Macro Problems

Keep an Excel VBA UserForm Text Box Scrolled to the Top

Maira MehtabMaira Mehtab Nov 18, 2026 869 views

Question details

Keep a VBA UserForm text box at the beginning of its content when the form opens and when the user clicks it.

Keep an Excel VBA UserForm Text Box Scrolled to the Top
Product
Microsoft Excel VBA UserForm
Device & OS
not provided
Scenario
A UserForm loads text into a text box with a vertical scrollbar, and the user wants to reset its position in the Initialize event.
Observed behavior
The text box scrolls to the bottom when the form opens or when the user clicks inside it.
Before you start

Open the workbook in Excel and enable macros if prompted. In the VBA editor, identify the UserForm, the text box name, and where its text is populated.

Solution 1Recommended

Reset the text box selection after loading its content

Use the Initialize event to place the caret at the beginning, then reset it after the form becomes active if needed.

Replace TextBox1 with the name of your control. Set the selection after assigning the text; later changes to the text or focus can move the position again.

A control may not be ready to receive focus during Initialize. If the initial reset alone does not keep the beginning visible, use the Activate event after the form is displayed.

1
Open the form's code

Press Alt+F11, find the UserForm in Project Explorer, and open its code window. Select UserForm from the object list and Initialize from the procedure list.

2
Reset after loading text

In the existing UserForm_Initialize procedure, add these lines after the code that populates the text box: TextBox1.SelStart = 0 TextBox1.SelLength = 0

3
Reset after the form appears

If the text still opens at the bottom, select UserForm and Activate in the code window and add: Private Sub UserForm_Activate() TextBox1.SetFocus TextBox1.SelStart = 0 TextBox1.SelLength = 0 End Sub

4
Test the form

Run the form from Excel or select it in the VBA editor and press F5. Check that the beginning of the text is visible; if other code changes the text later, place the reset after that code too.

Reset the text box selection after loading its content
Focus and event timing: The Activate event can run again when the form is reactivated, and SetFocus moves focus to the text box. An Initialize-only reset may not prevent a later click or focus change from moving the view.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move everyday spreadsheet work. It does not fix Excel UserForm behavior; check VBA and UserForm compatibility before migrating macro-dependent workbooks.

Open and edit spreadsheets in a familiar interfaceCompatible with common Microsoft Excel formats, including XLSX and XLSWork with spreadsheet data in a lightweight office suiteUse a free alternative for everyday spreadsheet tasks
microsoft office alternative - wps office

Frequently Asked Questions

Why might SetFocus fail in UserForm_Initialize?

The form or control may not yet be ready to receive focus. Set SelStart after loading the text in Initialize, and use UserForm_Activate for SetFocus if the reset needs to occur after the form appears.

What should I do if the text is loaded after Initialize?

In the procedure that assigns TextBox1.Text, add TextBox1.SelStart = 0 and TextBox1.SelLength = 0 immediately after the assignment.

Can I keep the text box at the top when it is clicked?

Add a MouseUp event for the text box and set SelStart and SelLength to 0. This also prevents users from positioning the caret or selecting text normally with the mouse.

Why does the position change when the form is shown again?

Initialize runs when the form is loaded, not every time a hidden form is shown. Use the UserForm_Activate event if the reset must also run when the form becomes active again.