ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Convert a number to text and add a comma separator for thousands (https://www.excelbanter.com/excel-programming/378946-convert-number-text-add-comma-separator-thousands.html)

prahz

Convert a number to text and add a comma separator for thousands
 
I have a Text Box in a User Form that I am creating. The Text Box's
value is set to a number without decimals.

For example:
Dim rents As Long
rents = 4102
rentsTxtBox.Value = rents

So when the number passes to the Text Box, I want it to display like
this: 4,102. Basically, is there an vba function for excel that
converts a number to a string and then adds the comma separator for
thousands? If not what code would I use to do this?

Thanks.


[email protected]

Convert a number to text and add a comma separator for thousands
 
Hi
In VBA use
Format(rents, "#,##0")

The #,##0 is a custom number format in Excel that you can see in
Format, Cells..., Custom.
regards
Paul

prahz wrote:

I have a Text Box in a User Form that I am creating. The Text Box's
value is set to a number without decimals.

For example:
Dim rents As Long
rents = 4102
rentsTxtBox.Value = rents

So when the number passes to the Text Box, I want it to display like
this: 4,102. Basically, is there an vba function for excel that
converts a number to a string and then adds the comma separator for
thousands? If not what code would I use to do this?

Thanks.



prahz

Convert a number to text and add a comma separator for thousands
 
Thank you!

wrote:
Hi
In VBA use
Format(rents, "#,##0")

The #,##0 is a custom number format in Excel that you can see in
Format, Cells..., Custom.
regards
Paul

prahz wrote:

I have a Text Box in a User Form that I am creating. The Text Box's
value is set to a number without decimals.

For example:
Dim rents As Long
rents = 4102
rentsTxtBox.Value = rents

So when the number passes to the Text Box, I want it to display like
this: 4,102. Basically, is there an vba function for excel that
converts a number to a string and then adds the comma separator for
thousands? If not what code would I use to do this?

Thanks.




All times are GMT +1. The time now is 05:38 PM.

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