Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Ensuring Standard Units During Data Entry.
Written by Allen Wyatt (last updated December 19, 2018)
This tip applies to Excel 97, 2000, 2002, and 2003
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, 15nile, 15 ni, 15 mu, 15mi, 15mi., 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 CONVERT function is part of the Analysis ToolPak. 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 (7608) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Ensuring Standard Units During Data Entry.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
Two lists of similar data can be challenging to synchronize. Here are some ways that you can align data in two different ...
Discover MoreTired of the Find and Replace dialog box blocking the view of your worksheet when you are searching for information? Do ...
Discover MoreDon't want to always type the decimal point as you enter information in a worksheet? If you are entering information that ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments