Create an input mask on a text box

svmac

Board Regular
Joined
Feb 16, 2002
Messages
182
I have a userform, containing various items that all do exactly what I need - except for one particular textbox.

The user enters an interest rate in this box, but I don't want it to create a problem if they enter 4.99 as a number, rather than 4.99%. Is there a way to create an input mask or something similar that automaticall appends the % to the end of the number as it is typed?
Thanks in advance,
Stuart Macdonald
_________________
Business Analyst
Australian Central Credit Union Ltd
http://www.accu.com.au
This message was edited by svmac on 2002-08-29 17:15
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
L

Legacy 98055

Guest
Hi
It would somewhat more complicated to append the % as the text is typed. Using the BeforeUpdate event should do well enough.
<pre>
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not Right(TextBox1, 1) = "%" Then TextBox1 = TextBox1 & "%"
End Sub

</pre>
Tom
 

svmac

Board Regular
Joined
Feb 16, 2002
Messages
182
Thnx for the reply Tom.

I managed to work out another method that will suit me.

I placed % as the value of the RateTextBox properties, and then added the following to the UserForm_Initialize() sub:

Private Sub UserForm_Initialize()
RateTextBox.SetFocus
RateTextBox.CurX = 0
End Sub

This places the cursor at the start of the text box, in front of the % sign. Should sort me out - if it doesn't, I will give your method a go.

Many thanks
Stuart Macdonald
 

Forum statistics

Threads
1,148,222
Messages
5,745,467
Members
423,952
Latest member
EduardoM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top