VBA & Macro Problems

Select the Last Word in an Excel VBA UserForm ComboBox

John WilsonJohn Wilson Nov 18, 2026 871 views

Question details

Select the final word in a UserForm ComboBox after the user chooses an item.

Select the Last Word in an Excel VBA UserForm ComboBox
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
An Excel VBA UserForm contains a ComboBox whose selected item may contain multiple words.
Observed behavior
The Change event can select all the text or run before the final selection is reflected in the control.
Before you start

Open the workbook in a desktop version of Excel that supports VBA, and enable macros if prompted. In the VBA editor, confirm the ComboBox name and make sure its Style property allows text editing.

Solution 1Recommended

Select the Last Word from ComboBox Events

Use the Enter and DropButtonClick events to apply a selection based on the current ComboBox value.

SelStart uses a zero-based character position, and SelLength controls how many characters are highlighted. The helper below ignores trailing spaces when finding the last word.

Event timing can vary: DropButtonClick may run before the new item is committed. Test the result with your control and use the button-based solution if the selection is overwritten or uses the old value.

1
Open the UserForm code

Press Alt+F11 in Excel, find the UserForm in Project Explorer, and open its code window. Replace ComboBox1 in the following code if your control has a different name.

2
Add the selection helper

In the UserForm code window, add: Private Sub SelectLastWord(ByRef cb As MSForms.ComboBox) Dim s As String Dim lastSpace As Long s = RTrim$(cb.Value & "") If Len(s) = 0 Then cb.SelLength = 0 Exit Sub End If lastSpace = InStrRev(s, " ") cb.SelStart = lastSpace cb.SelLength = Len(s) - lastSpace End Sub

3
Connect the events

Add these event procedures to the same UserForm code window, or merge their calls into existing procedures: Private Sub ComboBox1_Enter() SelectLastWord ComboBox1 End Sub Private Sub ComboBox1_DropButtonClick() SelectLastWord ComboBox1 End Sub

4
Set the focus behavior and test

Select ComboBox1 in the UserForm designer and set EnterFieldBehavior to fmEnterFieldBehaviorRecallSelection in the Properties window. Run the form, choose an item, and check whether its final word remains highlighted.

Select the Last Word from ComboBox Events
Check the event timing: DropButtonClick does not guarantee that the newly chosen value is already available. If the old word or all text is selected, use an explicit button click after the choice is complete.
Free Microsoft Office alternative

Work with Excel-Compatible Spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Excel files. It can help you move everyday spreadsheet work to WPS, although Excel VBA UserForm compatibility depends on the WPS version and environment.

Open and edit Microsoft Excel XLSX and XLS files.Use a familiar spreadsheet interface for everyday workbook tasks.Move compatible spreadsheet files between Excel and WPS Office.Keep working with spreadsheet data while checking macro compatibility separately.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the ComboBox Change event select the wrong text?

Change can occur while the control is still processing an interaction, and a later update may replace the selection. Test Enter and DropButtonClick, or apply the selection from a button after the user has chosen an item.

What do SelStart and SelLength do?

SelStart sets the zero-based position where the selection begins, and SelLength sets its character count. For the last word, use InStrRev to find the final space and calculate the remaining length.

How can I stop the ComboBox from selecting all text when it receives focus?

In the UserForm designer, select the ComboBox and set EnterFieldBehavior to fmEnterFieldBehaviorRecallSelection in the Properties window. Then set SelStart and SelLength for the selection you want.

What if the ComboBox contains only one word or trailing spaces?

The helper uses RTrim$ to ignore trailing spaces. If there is no space within the remaining text, InStrRev returns zero, so the whole word is selected.

Can I use the same Excel VBA UserForm code in WPS Office?

VBA and UserForm support can vary by WPS version and environment. Test the workbook and its controls in your specific installation; WPS Office does not directly fix Excel's ComboBox event behavior.