number variable format in VBA

DRaffo

New Member
Joined
Jul 12, 2007
Messages
6
Is there any way to format a number variable in VBA, maybe when declaring it, so that it is displayed with the 3rd number coma and 2 decimal places? ie. 3,556.98
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Code:
Sub test2()
Dim x, y As String
x = 3556.98
y = Format(x, "#,000.00")
MsgBox y
End Sub
 
Upvote 0
How are you displaying it? If is a Message Box, do something like this:
Code:
    Dim myValue As Double
    myValue = 3556.98
    
    MsgBox Format(myValue, "#,##0.00")
 
Upvote 0
thanks for the quick reply!

both gave me what i needed.

its use was to later be displayed in excel in the middle of a string:

Code:
pounds = tons * 2204.62262

pounds2 = Format(pounds, "#,000.00")

Cells(40, 2) = "Total weight is " & pounds2 & " pounds"
 
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top