I meant the exit event of the textbox. In a new/blank workbook, create a userform with three textboxes.Originally Posted by av8tordude
[vba]Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim MeCtl As MSForms.TextBox
Set MeCtl = Me.ActiveControl
TrimLeft MeCtl
Me.Caption = ">" & MeCtl.Value & "<"
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim MeCtl As MSForms.TextBox
Set MeCtl = Me.ActiveControl
TrimLeft MeCtl
Me.Caption = ">" & MeCtl.Value & "<"
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim MeCtl As MSForms.TextBox
Set MeCtl = Me.ActiveControl
TrimLeft MeCtl
Me.Caption = ">" & MeCtl.Value & "<"
End Sub
Private Function TrimLeft(ByRef tb As MSForms.TextBox)
tb.Value = LTrim(tb.Value)
End Function[/vba]
You can watch the userform's caption to see that the values entered into whichever textbox are trimmed on the left (leading spaces) upon exiting the textbox.
What exactly are you wanting to do? I ask as I would suspect that trimming in the textbox is not the issue. Wouldn't we be more likely be concerned with what is happening with the textbox's value as it affects other parts of the code (ie - the val stored in the variable). I hope that makes sense.
Mark