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
 

Some videos you may like

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

Hlatigo

Well-known Member
Joined
Jun 3, 2002
Messages
677
Thanks Erik

I think i can accomplish it based on a change event. Was just hoping to do it another way. thanks a bunch!!
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,059
Office Version
  1. 365
Platform
  1. Windows
How are these textboxes actually being populated?

Is it from a worksheet or from user input?

Why not format on the Exit event?
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,521
Messages
5,572,628
Members
412,475
Latest member
JaredNAU
Top