Friday, July 22, 2016

Turning Inches into Feet and Inches -- even fractions of an inch...

Turning inches into feet is simple math... but why not have a function that does it and the output looks better than if I did it by hand.   Given an integer that represents inches this little Excel VBA function will output feet and inches.

=====================code below===============================
Public Function IntoFeet(ininches As Double) As String
Dim feet As Integer
Dim inches As Double
    feet = Int(ininches / 12)
    inches = ininches - (feet * 12)
    IntoFeet = feet & "' " & Trim(Excel.WorksheetFunction.Text(inches, "#-?/?")) & """" 'formats thte output including fractions
End Function
=================================================================


I'm sure there are a lot of things I can do to improve this function, but if you have some ideas, drop me a comment!

Thanks-

No comments:

Post a Comment