Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8675305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:55:05+00:00 2026-06-12T19:55:05+00:00

Below is a VBA function that I created for use in Excel for converting

  • 0

Below is a VBA function that I created for use in Excel for converting a measurement of feet from a number to text. For instance, the function will take the number 1.5 and convert it to the string: 1′-6″.

For some reason though, it is incorrectly rounding the value of 11.5-inches. When a cell is set to ‘=11.5/12′ (11.5-inches expressed as feet) the result is 0.9583 with the 3 repeating. When I then pass this value to my txtfeet() function, it returns the string 1’-0″. The real answer should be the string 11 1/2″.

The function works fine for other repeating numbers like 9.5-inches (0.7916 with the 6 repeating). Weirdly, it also works fine if I pass it 1-ft and 11.5-inches (in other words, 1.9583 with the 3 repeating).

Can anyone help fix this error?

Here is the code for my function.

Public Function txtfeet(FeetIn As Double, Optional Denominator As Integer = 8)

' This function will change a decimal number of feet (FeetIn) to the text string
' representation of feet, inches, and fractional inches.
'
' It will round the fractional inches to the nearest 1/x where x is the denominator
' and is given by the user as the second argument of this function.  If a denominator
' is not given, it defaults to 8 as shown above.
'
' Modified from MrExcel.com

    ' set a variable to the integer portion of FeetIn
    NbrFeet = Fix(FeetIn)

    ' set a variable to the number of inches in decimal form
    InchIn = (FeetIn - NbrFeet) * 12

    ' set a variable to the integer portion of InchIn
    NbrInches = Fix(InchIn)

    ' set a variable to the remaining fractional inches in decimal form
    FracIn = (InchIn - NbrInches) * Denominator

    ' set a variable to be FracIn rounded to the nearest whole number
    Numerator = Application.WorksheetFunction.Round(FracIn, 0)

    ' if the fractional inches are zero, define the portion of text
    ' that will represent the fractional inches to be blank
    If Numerator = 0 Then
        FracText = ""

    ' otherwise, if the number of inches plus the fractional inches rounds up to
    ' 12, add one to NbrFeet and set NbrInches to zero and FracText to blank
    ElseIf (InchIn + (Numerator / Denominator)) = 12 Then
        NbrFeet = NbrFeet + 1
        NbrInches = 0
        FracText = ""

    ' otherwise, if the numerator equals the denominator, add one to NbrInches
    ' and set FracText to blank
    ElseIf Numerator = Denominator Then
        NbrInches = NbrInches + 1
        FracText = ""

    ' otherwise, define FracText in its simplest fractional form
    Else
        ' use a loop to get the fractional inches to their simplest form
        Do
            ' if the numerator is even, divide both numerator and divisor by 2
            If Numerator = Application.WorksheetFunction.Even(Numerator) Then
                Numerator = Numerator / 2
                Denominator = Denominator / 2
            Else
                FracText = " " & Numerator & "/" & Denominator
                Exit Do
            End If
        Loop
    End If

    ' define the output of the function as a text string of feet, inches, and
    ' fractional inches or just inches and fractional inches if NbrFeet is zero
    ' or just fractional inches if both NbrFeet and NbrInches are zero
    If NbrFeet = 0 And NbrInches = 0 And Numerator = 0 Then
        txtfeet = "0"""
    ElseIf NbrFeet = 0 And NbrInches = 0 Then
        txtfeet = Application.WorksheetFunction.Trim(FracText) & """"
    ElseIf NbrFeet = 0 Then
        txtfeet = NbrInches & FracText & """"
    Else
        txtfeet = NbrFeet & "'-" & NbrInches & FracText & """"
    End If

End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:55:07+00:00Added an answer on June 12, 2026 at 7:55 pm

    I believe your line

    ElseIf (InchIn + (Numerator / Denominator)) = 12 Then
        NbrFeet = NbrFeet + 1
        NbrInches = 0
        FracText = ""
    

    should be

    ElseIf (NbrInches + (Numerator / Denominator)) = 12 Then
       NbrFeet = NbrFeet + 1
    NbrInches = 0
    FracText = "
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am not that skilled at Excel/VBA and need some help. The code below (in
I have the below SQL Script which is run from Excel VBA using ADO
Greetings, The VBA code below will create an Excel QueryTable object and display it
Below is the code from a plugin I use for sitemaps. I would like
I have this code below to copy VBA codes from one word document to
In excel vba I have added a commandbutton to userform... like below Set ctrl
The following VBA subroutine will run most queries just fine. (ie: SELECT * FROM
I found a nifty RegEx function that I'm using (see below). The function outputs
The code below is VBA for Excel. I am using the Visual Basic editor
I have created this function GetSubName that I need to return the name that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.