I am writing an application in excel that helps you to learn the Completing the Square process. I want the cell to be formatted as Number if the variable is an integer, and formatted as a fraction if not.
If h = (Int(h)) Then
Range("D1").Select
Selection.NumberFormat = "Number"
Else
Range("D1").Select
Selection.NumberFormat = "?/?"
End If
This code doesn’t work for some reason, giving me the following error:
Unable to set the NumberFormat property of the Range class
Are there any other ways I can do this?
Try:
However, if you format an integer as a fraction, it’ll still show as an integer (i.e. “1” as a fraction is still “1”). So why not just format it as a fraction regardless?