Option Explicit
Public Function convertInches(inchesToConvert) 'inchesToConvert
Dim Holder 'inchesToConvert
Dim inchesLeft
Dim inchesRight
Dim inches
Holder = inchesToConvert
Dim Feetdec As Single
Feetdec = CStr(Holder / 12) ' inches converted to Feet
Dim feetLeft
On Error Resume Next
feetLeft = Left(Feetdec, InStrRev(Feetdec, ".") - 1) ' calculating feet no decimal place
If Err.Number <> 0 Then
Err.Clear
feetLeft = Feetdec
End If
inches = Holder - (feetLeft * 12)
inchesRight = CSng(Right(inches, Len(inches) - InStrRev(inches, ".") + 1)) ' problem if inches are right on.
If InStrRev(inchesRight, ".") = 0 Then
inchesRight = 0
End If
On Error Resume Next
inchesLeft = CSng(Left(inches, InStrRev(inches, ".") - 1))
If Err.Number <> 0 Then
inchesLeft = inches
End If
Dim Formatedfraction
Select Case inchesRight
Case Is = 0
Formatedfraction = vbNullString
Case Is <= 0.125
Formatedfraction = " 1/8"
Case Is <= 0.1875
Formatedfraction = " 3/16"
Case Is <= 0.25
Formatedfraction = " 1/4"
Case Is <= 0.3125
Formatedfraction = " 5/16"
Case Is <= 0.375
Formatedfraction = " 3/8"
Case Is <= 0.4375
Formatedfraction = " 7/16"
Case Is <= 0.5
Formatedfraction = " 1/2"
Case Is <= 0.5625
Formatedfraction = " 9/16"
Case Is <= 0.625
Formatedfraction = " 5/8"
Case Is <= 0.6875
Formatedfraction = " 11/16"
Case Is <= 0.75
Formatedfraction = " 3/4"
Case Is <= 0.8125
Formatedfraction = " 13/16"
Case Is <= 0.875
Formatedfraction = " 7/8"
Case Is <= 1
Formatedfraction = vbNullString
inchesLeft = inchesLeft + 1
End Select
convertInches = feetLeft & "'" & "-" & "" & inchesLeft & "" & Formatedfraction & Chr(34)
End Function