Formatting textbox currency on userform

  • Thread starter Thread starter gki
  • Start date Start date
G

gki

Hello,

I am trying to format the textboxes on userform with the followin
code, but I cannot see the problem why I cannot make it working....

For i=1 To 21

With "price0" & (i)
.value=Format (.value, "£#,##0.00")
End With

Next i

my textbox names are : price01, price02, price03......

Please assist me to make it work,

Regards,

gk
 
Hi gki,

Try something like:

Dim i As Long
Dim ctrl As Control

For Each ctrl In UserForm1.Controls
If TypeOf ctrl Is MSForms.TextBox Then
For i = 1 To 21
If ctrl.Name = "price0" & i Then
ctrl.Value = Format(ctrl.Value, "£#,##0.00")
End If
Next i
End If
Next
 
An another possibility

For i = 1 To 21
With Userform1.Controls("price0" & i)
.value = Format(.Value, "£#,##0.00")
End With
Next i

if they are named price09, price10, (rather than price010) then you would
need to do

For i = 1 To 21
With Userform1.Controls("price" & format(i,"00"))
.value = Format(.Value, "£#,##0.00")
End With
Next i

--
Regards,
Tom Ogilvy

Norman Jones said:
Hi gki,

Try something like:

Dim i As Long
Dim ctrl As Control

For Each ctrl In UserForm1.Controls
If TypeOf ctrl Is MSForms.TextBox Then
For i = 1 To 21
If ctrl.Name = "price0" & i Then
ctrl.Value = Format(ctrl.Value, "£#,##0.00")
End If
Next i
End If
Next
 
Back
Top