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.
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?
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?