text box percent field

S

Spencer Hutton

is there a way to have a text box on a userform automatically be set up to
receive a percent number amount? a user would be typing in, say...40%. i
would like if the text box could already have a percent sign and whatever
they type in the text box would be followed by that percent sign. i tried,
Userform.TextBox.Value = Userform.TextBox.Value & "%"
but that just repeated itself until the character max was filled. TIA.
 
T

Tom Ogilvy

Userform.TextBox.Value =
Application.Substitute(Userform.TextBox.Value,"%","") & "%"
 
C

Charles

Spencer,

You could try this.

Private Sub textbox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger
ByVal Shift As Integer) 'tab key
Application.ScreenUpdating = False
If KeyCode = "9" Or KeyCode = "13" Then
With UserForm1
.TextBox1.Text = .TextBox1.Text & " " & "%"
End With
End If
End Sub

When the user tabs off or press the enter key the % will be placed i
the textbox.

Charle
 
Top