ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Number Formats In A UserForm TextBox (https://www.excelbanter.com/excel-programming/314469-number-formats-userform-textbox.html)

Minitman[_4_]

Number Formats In A UserForm TextBox
 
Greetings,

I have a TextBox on a UserForm that I need to format as currency with
the Exit event. I can't seem to find what the correct syntax is for
this to happen.

Anyone have any ideas on how this should look?

TIA

-Minitman

Frank Kabel

Number Formats In A UserForm TextBox
 
Hi
if you want this as string value have a look at the format method. e.g.
var=format(textbox1.value,"0.00 $")

--
Regards
Frank Kabel
Frankfurt, Germany

"Minitman" schrieb im Newsbeitrag
...
Greetings,

I have a TextBox on a UserForm that I need to format as currency with
the Exit event. I can't seem to find what the correct syntax is for
this to happen.

Anyone have any ideas on how this should look?

TIA

-Minitman



Sharad Naik

Number Formats In A UserForm TextBox
 
Follwoing code will format it to $1,234.56 format:
Put it in to TextBox Exit event.

TextBox1.Value = Format(TextBox1.Value, """$""#,##0.00")

Sharad

"Minitman" wrote in message
...
Greetings,

I have a TextBox on a UserForm that I need to format as currency with
the Exit event. I can't seem to find what the correct syntax is for
this to happen.

Anyone have any ideas on how this should look?

TIA

-Minitman




Tom Ogilvy

Number Formats In A UserForm TextBox
 
You don't need to double-double quote the $ sign

s# = 1234.56
? Format(s, """$""#,##0.00")
$1,234.56
? format(s,"$ #,##0.00")
$ 1,234.56

I added a space in the second, but that makes no difference: (just for
clarity)
? format(s,"$#,##0.00")
$1,234.56

so for the OP

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.Text = format(cdbl(Textbox1.Text),"$ #,##0.00")
End Sub

or (cdbl is optional - excel will coerce the string)

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.Text = format(Textbox1.Text,"$ #,##0.00")
End Sub




--
Regards,
Tom Ogilvy

"Sharad Naik" wrote in message
...
Follwoing code will format it to $1,234.56 format:
Put it in to TextBox Exit event.

TextBox1.Value = Format(TextBox1.Value, """$""#,##0.00")

Sharad

"Minitman" wrote in message
...
Greetings,

I have a TextBox on a UserForm that I need to format as currency with
the Exit event. I can't seem to find what the correct syntax is for
this to happen.

Anyone have any ideas on how this should look?

TIA

-Minitman






Sharad Naik

Number Formats In A UserForm TextBox
 
Yes, for standard currency symbol no need to double-dobule quote. For
currency symbol not appearing in the cell number format in excel, double
quote is needed.

Sharad

"Tom Ogilvy" wrote in message
...
You don't need to double-double quote the $ sign

s# = 1234.56
? Format(s, """$""#,##0.00")
$1,234.56
? format(s,"$ #,##0.00")
$ 1,234.56

I added a space in the second, but that makes no difference: (just for
clarity)
? format(s,"$#,##0.00")
$1,234.56

so for the OP

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.Text = format(cdbl(Textbox1.Text),"$ #,##0.00")
End Sub

or (cdbl is optional - excel will coerce the string)

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.Text = format(Textbox1.Text,"$ #,##0.00")
End Sub




--
Regards,
Tom Ogilvy

"Sharad Naik" wrote in message
...
Follwoing code will format it to $1,234.56 format:
Put it in to TextBox Exit event.

TextBox1.Value = Format(TextBox1.Value, """$""#,##0.00")

Sharad

"Minitman" wrote in message
...
Greetings,

I have a TextBox on a UserForm that I need to format as currency with
the Exit event. I can't seem to find what the correct syntax is for
this to happen.

Anyone have any ideas on how this should look?

TIA

-Minitman








Tom Ogilvy

Number Formats In A UserForm TextBox
 
Not exactly true either. As long as the characters used are not formatting
characters, there is no need:

? format(1234.56,"AB#,##0.00")
AB1,234.56


AB certainly isn't a standard currency symbol.

ABC causes problems:
? format(1234.56,"ABC#,##0.00")
AB5/18/1903 1:26:24 PM#,##0.00

but you can fix that with
? format(1234.56,"AB\C#,##0.00")
ABC1,234.56


--
Regards,
Tom Ogilvy

"Sharad Naik" wrote in message
...
Yes, for standard currency symbol no need to double-dobule quote. For
currency symbol not appearing in the cell number format in excel, double
quote is needed.

Sharad

"Tom Ogilvy" wrote in message
...
You don't need to double-double quote the $ sign

s# = 1234.56
? Format(s, """$""#,##0.00")
$1,234.56
? format(s,"$ #,##0.00")
$ 1,234.56

I added a space in the second, but that makes no difference: (just for
clarity)
? format(s,"$#,##0.00")
$1,234.56

so for the OP

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.Text = format(cdbl(Textbox1.Text),"$ #,##0.00")
End Sub

or (cdbl is optional - excel will coerce the string)

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.Text = format(Textbox1.Text,"$ #,##0.00")
End Sub




--
Regards,
Tom Ogilvy

"Sharad Naik" wrote in message
...
Follwoing code will format it to $1,234.56 format:
Put it in to TextBox Exit event.

TextBox1.Value = Format(TextBox1.Value, """$""#,##0.00")

Sharad

"Minitman" wrote in message
...
Greetings,

I have a TextBox on a UserForm that I need to format as currency with
the Exit event. I can't seem to find what the correct syntax is for
this to happen.

Anyone have any ideas on how this should look?

TIA

-Minitman









Minitman[_4_]

Number Formats In A UserForm TextBox
 
Hey Tom,

Thanks for the answer and the lesson. It always helps to understand
how the answer works.

-Minitman




On Sat, 23 Oct 2004 10:20:07 -0400, "Tom Ogilvy"
wrote:

You don't need to double-double quote the $ sign

s# = 1234.56
? Format(s, """$""#,##0.00")
$1,234.56
? format(s,"$ #,##0.00")
$ 1,234.56

I added a space in the second, but that makes no difference: (just for
clarity)
? format(s,"$#,##0.00")
$1,234.56

so for the OP

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.Text = format(cdbl(Textbox1.Text),"$ #,##0.00")
End Sub

or (cdbl is optional - excel will coerce the string)

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Textbox1.Text = format(Textbox1.Text,"$ #,##0.00")
End Sub




All times are GMT +1. The time now is 03:45 AM.

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