Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, 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: Ensuring Standard Units During Data Entry.

# Ensuring Standard Units During Data Entry

Written by Allen Wyatt (last updated December 16, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021

Sharon has a worksheet that she uses to record distances. Several people enter data into the worksheet and some enter the distance in miles (such as 15 m) and others enter the distance in kilometers (such as 28 Km). Sharon wonders if there is a formula she can use to convert whatever is placed into the cell into kilometers so that all answers are the same?

There are formulas you can use to do the conversion, but before getting to them it would be a good idea to consider how you are putting your worksheet together. From a data management standpoint, it is not a good idea to allow people to specify units in the same cell as the value entry. The problem is that you will never be able to trap all the possible user mistakes and typos. For instance, someone could enter 15 miles as one of the following: 15 miles, 15 mile, 15miles, 15mi, 15mile, 15 mi, 15 ms, 15ms, etc. The same problem occurs with km entry.

A good idea is to split the value from the units designation. For instance, you could allow someone to put a value into cell B4 and then in cell C4 they could enter a designator as to whether the value represents miles or kilometers. You can use data validation on the cell to limit acceptable choices for their entry. The result is a more "bulletproof" method of data entry.

That being said, let's examine a few ideas for doing your data conversion. Excel provides a cool CONVERT function that allows you to, oddly enough, perform data conversions from one measurement system to another. The formula to convert from miles to kilometers would be as follows:

```=CONVERT(B4,"mi","km")
```

If you would like to know all the units of measurement you can specify with the CONVERT function, Excel's online help system should be up to the task.

If you use cell C4 to specify a unit of measure (either "mi" or "km"), then the following formula could be used to always make sure that whatever was entered in cell B4 was expressed in kilometers:

```IF(C4="mi",CONVERT(B4,"mi","km"),B4)
```

If you aren't able to split the units of measurement into a different cell, then you are left to try to do some data conversion on what is entered. The important thing to remember is that whatever is entered is treated by Excel as a text value since it contains non-numeric characters.

Let's assume for a second that someone enters into cell B4 the value "5 mi" without the quote marks. You need to use a formula to strip off the non-numeric characters

```=IF(RIGHT(SUBSTITUTE(B4," ",""),2)="mi",CONVERT(VALUE(
LEFT(B4,LEN(B4)-2)),"mi","km"),VALUE(LEFT(B4,LEN(B4)-2)))
```

The formula looks at the value in cell B4 and specifically examines the two right-most characters, after any spaces in the cell have been removed. If those two characters are "mi" (without the quotes, of course) then the CONVERT function is used to do a conversion on the numeric portion of the cell. If the two right-most characters are anything other than "mi" then the formula simply returns the numeric portion of the cell without any change.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3593) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Ensuring Standard Units During Data Entry.

##### 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

One of the strong suits of macros is that they can process the information in a document quickly and reliably. For ...

Discover More

Stepping Through a Macro with a Worksheet Visible

When developing a macro, it is often necessary to step through the various code lines so you can see what is happening on ...

Discover More

Incorrect Suggested Correction

As you type your document, Word flags words and phrases it thinks may be incorrect. The source of these various flaggings ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

##### More ExcelTips (ribbon)

Separating a Date into Component Columns

Do you need a way to split dates out into the individual parts that make up that date? This tip provides two easy ways ...

Discover More

Combining Multiple Rows in a Column

Do you need to concatenate the contents of a range of cells in the same column? Here's a formula and a handy macro to ...

Discover More

Using the Same Range Name on Different Worksheets

Defined names can be a great boon when working in a worksheet. Usually names are available throughout an entire workbook, ...

Discover More
##### Subscribe

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

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 one more than 7?

2023-12-17 17:13:04

Tomek

What a can of worms? How do you assure that the person entering information pays attention to the value but also verifies the unit?
And does "m" mean miles or meters?
If I were to design such an input sheet I would force the user to select the unit from an unambiguous list, whenever the value was entered. Obviously, I would split the value and the unit into two neighbouring cells, say column A for distances and column B for units. Once both were entered, a formula could convert the entry into standard units and place the result elsewhere in the sheet.

I guess, it would be possible to create a macro that, upon selecting the unit, would convert the entered number into required units in the same cell where it was entered, but it could be harder afterwards for the user to review the data they entered.

2023-12-17 05:06:14

Steve Jezard

How about, custom formatting column B as #,##0 "km" and enter an input message such as "Enter your claim in km's" using data validation.
As km's are shorter than miles you'll never be over stated. If we can assume this is for some kind of expenses claim then people will be highly incentivised to enter the correct distance in km's.
You can then do what ever calculation you require.

##### 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.