Can I display numbers as fractions in a message box

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,911
Using Excel 2010. I am attempting to display numbers as fractions in a message box.

Code:
Sub HowToDisplayFractionsInMsgBox()
    
    Dim sngInput As Single
    
    sngInput = 0.75
    'Selection.NumberFormat = "# ??/??"  works to format a cell (and what VBA records)
    '="Fraction is: " & TEXT(0.75, "###/###") works in a cell
    'This does not work:
    MsgBox "Decimal value is: " & sngInput & vbLf & _
        "Fractional value is: " & Format(sngInput, "# ??/??")
    'Nor does this:
    MsgBox "Decimal value is: " & sngInput & vbLf & _
        "Fractional value is: " & Format(sngInput, "# ##/##")

End Sub

I cannot find a valid fraction format reference in the VBA help or through various internet searches.

If there is no format setting for this I can develop code to calculate the appropriate numerator and denominator, but would prefer not to do so.

Does anyone know of a built in format that can display numbers as fractions in a message box?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
How about
Code:
    MsgBox "Decimal value is: " & sngInput & vbLf & _
        "Fractional value is: " & [COLOR=#ff0000]WorksheetFunction.Text(sngInput, "###/###")[/COLOR]
 
Upvote 0
Obvious in retrospect. Thanks very much.
It still looks like a bug (at least an inconstancy) in the VBA Format function to me.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,841
Members
449,051
Latest member
excelquestion515

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