PDA

View Full Version : How to get msgbox output with spaces between every three numbers?



alex009988
07-25-2019, 12:11 PM
Sub test()
Dim a As Double
a = 10000000.56
'Selection.Style = "Comma"
MsgBox "Output: " & a
End Sub

So I want to get 10000000.56 as 10 000 000.56 kinda AccountingForm.
Is there some inbuild function for msgbox to do that?
Or I should convert double to the string and use...?
Thanks in advance!

Alex

Artik
07-25-2019, 01:04 PM
Read about the Format function.

Artik

Paul_Hossler
07-25-2019, 03:20 PM
Yes, Format is the key, but can be weird if you want to do something too odd

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/format-function-visual-basic-for-applications?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev11.query%3 FappId%3DDev11IDEF1%26l%3Den-US%26k%3Dk(vblr6.chm1008925)%3Bk(TargetFrameworkMoniker-Office.Version%3Dv16)%26rd%3Dtrue


Debug test output



?format(12345678901234.12,"### ### ### ### ### ##0.00")
12 345 678 901 234.10




So try something like this




MsgBox "Output: " &
format(a, "### ### ### ### ### ##0.00")