formatting textbox in userform Initialize

Hlatigo

Well-known Member
Joined
Jun 3, 2002
Messages
677
I am wanting the text boxes to all be formatted prior to the data be entered, that way I dont have to to after_update or Change about 90 times. Is it possible to format all the textboxes in the initialize of the userform? Right now I get a invalid procedure call or arguement when the form is loaded. the code I have is below. I tried a couple of ways to format but still nothing :( THANKS for any help


Code:
Private Sub UserForm_Initalize()
        TextBox1.SetFocus
        
        
        TextBox1 = Format(TextBox1.Value, "$#,##0.00")
        TextBox3.Value = FormatCurrency(TextBox3.Value)
        TextBox4.Value = FormatCurrency(TextBox4.Value)
end sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hello, Hlatigo,

you cannot "pre"format a textbox as you would do with cells
you can only check the input when it is or preferably when it has been changed

if you need help doing this, feel free to ask

I would not include the "$" sign but put it in a lable, just my opinion.

you've got a typo
UserForm_Initialize
you need an "i"


kind regards,
Erik
 
Upvote 0
Thanks Erik

I think i can accomplish it based on a change event. Was just hoping to do it another way. thanks a bunch!!
 
Upvote 0
How are these textboxes actually being populated?

Is it from a worksheet or from user input?

Why not format on the Exit event?
 
Upvote 0
as you stated in your first post
that way I dont have to to after_update or Change about 90 times.
you don't have to code 90 times the same
you could actually use a classmodule
or
some code like

Code:
Private Sub Textbox1_change()
Call updatecode(1)
End sub
Private Sub Textbox2_change()
Call updatecode(2)
End sub
so all refering to one macro
example
Code:
Private Sub updatecode(nr As Integer)
Dim ctrl As Control
Set ctrl = Me.Controls("Textbox" & nr)
MsgBox ctrl.Name
End Subcode]

best regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,893
Messages
6,122,121
Members
449,066
Latest member
Andyg666

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
Back
Top