Ensuring that only whole numbers are entered into a cell or range of cells in Excel is crucial for maintaining data integrity, particularly when working with numerical data that should not include decimals or fractions. Here are five methods to ensure Excel whole number only inputs:
The Importance of Whole Number Entries
In many applications, from accounting to scientific calculations, whole numbers are essential. Allowing decimals or fractions where they shouldn't be can lead to errors in calculations, misinterpretations of data, and poor decision-making. Fortunately, Excel provides several ways to restrict user input to whole numbers only.
Method 1: Using Data Validation for Whole Numbers

One of the most straightforward methods to ensure whole number entries is by using Excel's Data Validation feature. Here's how:
- Select the cell or range of cells where you want to restrict input to whole numbers.
- Go to the "Data" tab in the ribbon.
- Click on "Data Validation" in the Data Tools group.
- In the Data Validation dialog box, under the "Settings" tab, select "Whole Number" from the "Allow" dropdown list.
- You can also set specific criteria, such as allowing only positive whole numbers.
- Click "OK" to apply the validation.
Setting Up Error Messages
Within the Data Validation dialog, you can also set up a custom error message that will appear if someone tries to enter a non-whole number into the validated cells. To do this:
- In the Data Validation dialog, go to the "Error Alert" tab.
- Check the box next to "Show error alert after invalid data is entered."
- Customize the title and error message as desired.
- Click "OK" to apply the changes.
Method 2: Using Formulas to Check for Whole Numbers

Another approach is to use formulas to check if a number is whole. This method is particularly useful when you need to perform actions based on whether a cell contains a whole number or not.
- Use the
MOD
function, which returns the remainder of a division operation. For example,=MOD(A1,1)
will return 0 if A1 is a whole number. - Combine the
MOD
function with anIF
statement to perform different actions based on whether the cell is a whole number or not.
Example formula:
=IF(MOD(A1,1)=0, "Whole Number", "Not a Whole Number")
Method 3: Using VBA Macros to Restrict Input

For more advanced control over user input, you can use VBA (Visual Basic for Applications) macros in Excel. This method requires some programming knowledge but offers the flexibility to enforce complex input rules.
- Press
Alt + F11
to open the VBA editor. - Insert a new module and write a macro that checks user input and restricts it to whole numbers.
- You can use the
Worksheet_Change
event to catch changes to specific cells or ranges.
Example VBA code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If IsNumeric(Target.Value) Then
If Target.Value - Int(Target.Value) <> 0 Then
MsgBox "Please enter a whole number."
Application.Undo
End If
End If
End Sub
Method 4: Using Conditional Formatting to Highlight Non-Whole Numbers

While not a hard restriction, using conditional formatting can visually highlight cells that contain non-whole numbers, prompting users to correct their input.
- Select the range of cells you want to format.
- Go to the "Home" tab in the ribbon.
- Click on "Conditional Formatting" in the Styles group.
- Select "New Rule."
- Choose "Use a formula to determine which cells to format."
- Enter a formula like
=A1-INT(A1)>0
, which checks if the cell value is not a whole number. - Format the cells as desired.
Method 5: Using Excel's Input Messages Feature

Another method to guide users to input whole numbers is by using Excel's Input Messages feature, part of the Data Validation functionality.
- Follow the steps to set up Data Validation as in Method 1.
- In the Data Validation dialog, under the "Input Message" tab, check the box next to "Show input message when cell is selected."
- Customize the title and input message as desired.
Example input message:
"Please enter a whole number. Decimals are not allowed."
Gallery of Whole Number Inputs in Excel
Whole Number Inputs in Excel









Engage with Us
We hope these methods have been helpful in ensuring that your Excel spreadsheets only accept whole number inputs. For more Excel tips and tricks, subscribe to our newsletter or follow us on social media. Share your favorite Excel hacks and challenges in the comments below, and we'll do our best to address them in future articles.