Written by Allen Wyatt (last updated November 13, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
Prakash would like to restrict input data in a cell such that it accepts only a maximum of 11 digits before the decimal point and, possibly, 2 digits after. The input can be either an integer or decimal value, but it can only have a maximum of 11 digits to the left of the decimal and 2 to the right. (Thus, 1234 or 1234.56 would be acceptable, but 1234.567 would not.) Prakash notes that Data Validation doesn't seem to work when you want to limit digits both before and after the decimal point.
Prakash is close to finding the answer, because Data Validation can actually be used. The trick is to create a custom formula that can be used for the validation. Here's a formula that will return either True or False, as is required for Data Validation:
=AND(A1=ROUND(A1,2),ABS(A1)<100000000000)
The formula tests two conditions using AND, with both conditions needing to be true. The first condition checks to make sure that no more than 2 digits are used to the right of the decimal point. The second condition compares the absolute value to make sure it is less than 12 digits. It checks against 12 digits so that a value such as 99999999999.99 is considered valid.
In order to use the formula in Data Validation, follow these steps:
Figure 1. The Data Validation dialog box.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13643) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Want to establish a "bottom limit" on what dates can be entered in a cell? This tip presents two different ways you can ...
Discover MoreIf you want to make sure that only unique values are entered in a particular column, you can use the data validation ...
Discover MoreWant to control what users put into a cell? It's easy to do using a feature called data validation, as described in this tip.
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 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.
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