|
-
Apr 16th, 2008, 09:30 AM
#1
Thread Starter
Member
[RESOLVED] Userform Textbox in percentage format
I have a textbox in a userform so when the user keys in a number, it automatically converts it to a percentage. However, when the user keys in a 0, nothing populates in the textbox. See my code below and let me know what I need to do in order to allow the value 0 to be entered.
Code:
Private Sub txtratio_Change()
txtratio.Value = Format(Val(txtratio.Value) / 100, "##%")
txtratio.SelStart = Len(txtratio.Value) - 1
End Sub
-
Apr 16th, 2008, 09:38 AM
#2
Re: Userform Textbox in percentage format
Code:
Private Sub txtratio_Change()
txtratio.Value = Format(Val(txtratio.Value) / 100, "#0%")
txtratio.SelStart = Len(txtratio.Value) - 1
End Sub
Use #0% (see above)
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Apr 16th, 2008, 10:21 AM
#3
Thread Starter
Member
Re: [RESOLVED] Userform Textbox in percentage format
-
Oct 2nd, 2015, 06:35 PM
#4
New Member
Re: [RESOLVED] Userform Textbox in percentage format
I know this is an old thread, but I found it while trying to debug a different root cause for the same symptom. So I'm posting my version of the problem and its solution for others who may wander in here with similar versions of this issue:
If the Textbox control has its LinkedCell (or ControlSource) property set to refer to a worksheet cell, or if VBA code explicitly copies data to and from a worksheet cell, then the problem may be that Excel’s cell formatting system is overriding the Textbox’s value format. The fix for this problem is to ensure that the targeted LinkedCell (or ControlSource) cell, or the explicitly written/read cell, is formatted to Text format (“@”) or Percentage format (“0.00%”, “#%”, etc.).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|