text box percent field

  • Thread starter Thread starter Spencer Hutton
  • Start date Start date
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.
 
Userform.TextBox.Value =
Application.Substitute(Userform.TextBox.Value,"%","") & "%"
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top