Consulting

Results 1 to 3 of 3

Thread: How to get msgbox output with spaces between every three numbers?

  1. #1

    How to get msgbox output with spaces between every three numbers?

    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

  2. #2
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Read about the Format function.

    Artik

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    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")
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •