Userform_Initialize is jsut an event procedure that goes in the userform.
If the format is all the same, you can do it in a loop like so
Private Sub UserForm_Initialize()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Then
ctl.Text = Format(ctl.Text, "#,##0.00")
End If
Next ctl
End Sub
A word of warning. If the textbox is linked to a worksheet cell (I assume
this), the formatting shown above is superceded. The only way I could get
around this was with this sort of code
Option Explicit
Dim t46_Controlsource As String
Dim t47_Controlsource As String
Private Sub TextBox46_AfterUpdate()
TextBox46.Text = Format(TextBox46.Text, "#,##0.00")
End Sub
Private Sub TextBox47_AfterUpdate()
TextBox47.Text = Format(TextBox47.Text, "#,##0.00")
End Sub
Private Sub UserForm_Activate()
TextBox46.Text = Format(TextBox46.Text, "#,##0.00")
TextBox47.Text = Format(TextBox47.Text, "#,##0.00")
End Sub
Private Sub UserForm_Initialize()
t46_Controlsource = TextBox46.ControlSource
t47_Controlsource = TextBox47.ControlSource
TextBox46.ControlSource = ""
TextBox47.ControlSource = ""
End Sub
Private Sub UserForm_Terminate()
Worksheets(1).Range(t46_Controlsource).Value = TextBox46.Text
Worksheets(1).Range(t47_Controlsource).Value = TextBox47.Text
End Sub
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
bruce forster said:
Bob:
I will try his suggestion but where is the UserForm_Initialize code??
Also, I have about 36 textboxes on the user form, is there any way to format
them simultaenously?
P
Also, I will be posting another question this evening and would really
appreciate your response. You have been very helpful.