Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Text box Formatting 1

Status
Not open for further replies.

SysDupe123

Technical User
Dec 17, 2003
74
US
I have a worksheet with some text bpxes on it for user input. I am trying to set up a format so that when the user inputs a number, it shows as a percentage, i.e., user enters 30, and text box shows 30%.
I have used some VB to set other text boxes to show $ for currency fields, but I cannot seem to get it to work for percentages.

Here is the code I used for the dollar sign:
TextBox13.Value = Format(TextBox13.Value, "$#,##0")

I tried to use this:
TextBox51.Value = Format(Val(TextBox51.Value) / 100, "##%")

This ended up giving me the percent sign, right as soon as a number was entered. If I needed to type 65, it would show 6% and not take the 5. The cursor defaults to after the % and I manually have to back up to make the text box read 65%.

Any ideas?
Thanks
 
I assume you have your code in the textbox's change event.

Code:
Private Sub TextBox1_Change()
TextBox1.Value = Format(Val(TextBox1.Value) / 100, "##%")
TextBox1.SelStart = Len(TextBox1.Value) - 1
End Sub
 
Thanks a million! I've been working on this thing for a while and this is the one part that has been bugging me to death!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top