Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Working with Imperial Linear Distances.

Working with Imperial Linear Distances

Written by Allen Wyatt (last updated September 23, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021


6

Peter asked if it was possible in Excel to create a custom number format that will deal with imperial linear distances, such as inches, feet, miles, etc. The short answer is that no, this is not possible. Excel works natively in the decimal system, and many imperial measuring systems are based on other numeric systems (feet on base 12, for instance). While custom formatting can change the way that numbers are displayed, it cannot perform the conversions necessary for imperial measurements.

Your best bet is to keep the different units of whatever imperial measurement you want in different cells. For instance, a distance of 3 miles, 428 feet, and 7 inches could be kept in three cells, one for miles, one for feet, and the other for inches. You could then write the formulas necessary to convert to whatever measurement system you desire. There are also Excel add-ins available around the Internet (a quick search will find them) that can allow you to use this technique to work with linear measurements.

Another approach is to develop a custom function or macro that would convert a value into a linear measurement and display it as text. You couldn't use the result in math functions, but it may give you want you want for your workbook. Consider, for example, the following simple macro:

Function N2MYFI(x) As String
    Dim x1 as Long
    Dim FinalAnswer As String

    x1 = x
    Distances = Array(63360, 36, 12, 1)
    
    FinalAnswer = ""
    For Each Item In Distances
        FinalAnswer = FinalAnswer & " " & Int(x1 / Item)
        x1 = x1 - Item * Int(x1 / Item)
    Next

    N2MYFI = Trim(FinalAnswer)
End Function

This function returns four numbers, in a string, that represent the number of miles, yards, feet, and inches (MYFI) in a raw value. It is assumed that the value fed to the function is in inches, such as the following:

=N2MYFI(100)

This returns the string "0 2 2 4", which means there are 0 miles, 2 yards, 2 feet, and 4 inches in 100 inches. The function could easily be changed to return the values in any format desired.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9752) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021. You can find a version of this tip for the older menu interface of Excel here: Working with Imperial Linear Distances.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Disabling Printing

Don't want your worksheets to be printed out? You can make it a bit harder to get a printout by applying the techniques ...

Discover More

Deleting a Bookmark

Create a bookmark and you may, at some future point, need to delete that bookmark. It's easy to do, as described in this tip.

Discover More

Replacing Asterisks with a Footnote

You can use Word's Find and Replace capabilities to replace text (like an asterisk) with a footnote. This tip explains ...

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Condensing Sequential Values to a Single Row

If you have a bunch of ZIP Codes or part numbers in a list, you may want to "condense" the list so that sequential series ...

Discover More

Pulling a Phone Number with a Known First and Last Name

When using an Excel worksheet to store data (such as names and phone numbers), you may need a way to easily look up a ...

Discover More

Getting Rid of Unused Range Names

Excel allows you to easily create names for different ranges in your workbook. If you ever want to clean up the list of ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is six more than 0?

2026-01-01 06:04:29

sandeep

Thanks Woolley


2025-12-31 12:56:21

J. Woolley

Here's my version of the UDF.

Function FactorInches(Inches As Double) As String
    Dim Nches As Long, Factor As Variant, n As Integer
    Nches = Inches
    Factor = VBA.Array(63360, " mi ", 36, " yd ", 12, " ft ", 1, " in")
    For n = 0 To 7 Step 2
        FactorInches = FactorInches & Int(Nches / Factor(n)) & Factor(n + 1)
        Nches = Nches Mod Factor(n)
    Next
End Function


2025-12-31 10:33:58

J. Woolley

@sandeep kothari
1. Confirm the formula =N2MYFI(100) is spelled the same as your UDF.
2. Put the UDF in a standard module like Module1, not a document module like ThisWorkbook or a class module like Class1. (See the VBE's Insert menu.)


2025-12-31 05:15:12

sandeep kothari

Thanks Woolley. In my UDF, the last letter in N2MYFI is I as in India, not l as in lazy or 1 as in 123.
Also, I did NOT include the following VBA statement in my module: Option Explicit.
Yet the error happened.


2025-12-30 11:39:36

J. Woolley

@sandeep kothari
The last letter in N2MYFI is I as in India, not l as in lazy or 1 as in 123. Also, do NOT include the following VBA statement in your module: Option Explicit


2025-12-29 11:11:22

sandeep kothari

Dear Allen
I tried the function but it threw up a "#NAME?" error.

I wrote the following function in a cell:
=N2MYFI(100)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.