Can I display numbers as fractions in a message box

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,915
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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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