Search code examples
excelvbatextboxuserform

Start and End Selection in textbox - VBA


How to determine the end point of text selection in the text box? for example: Start of 3 and select to 5 character in textbox1. 0000000 (Selection with the ability to edit selected text.)

enter image description here

Private Sub textbox1_change()
If TextBox1.TextLength = 7 Then
  With TextBox1
    .SetFocus
    .SelStart = 2
    .SelLength = Len(.Text)
  End With
End If
End Sub

Solution

  • In Text.SelLength = Len(.Text) , insert .SelLength = 3.