ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Formatting textbox currency on userform (https://www.excelbanter.com/excel-programming/305120-formatting-textbox-currency-userform.html)

gki[_11_]

Formatting textbox currency on userform
 
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

--
Message posted from http://www.ExcelForum.com


Norman Jones

Formatting textbox currency on userform
 
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

---
Regards,
Norman




"gki " wrote in message
...
Hello,

I am trying to format the textboxes on userform with the following
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,

gki


---
Message posted from http://www.ExcelForum.com/




Tom Ogilvy

Formatting textbox currency on userform
 
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" wrote in message
...
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

---
Regards,
Norman




"gki " wrote in message
...
Hello,

I am trying to format the textboxes on userform with the following
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,

gki


---
Message posted from http://www.ExcelForum.com/







All times are GMT +1. The time now is 07:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com