Keep an Excel VBA UserForm Text Box Scrolled to the Top
Question details
Keep a VBA UserForm text box at the beginning of its content when the form opens and when the user clicks it.

- 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.
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.
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.
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.
In the existing UserForm_Initialize procedure, add these lines after the code that populates the text box: TextBox1.SelStart = 0 TextBox1.SelLength = 0
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
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 after a mouse click
Use this additional event if clicking the text box moves the view away from the beginning and you want every click to return there.
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.

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.




