Check Integer Values and Decimal Separators in Excel VBA
Question details
Determine whether a number entered in an Excel VBA prompt is an integer while accounting for regional decimal separators.

- Product
- Microsoft Excel VBA
- Device & OS
- Windows; version not provided
- Scenario
- A VBA macro accepts numeric input on a system that may use a comma rather than a period as the decimal separator.
- Observed behavior
- Code that assumes a period as the decimal separator may interpret or reject input incorrectly under a regional configuration that uses a comma.
Check which decimal separator Windows uses and whether Excel is set to use system separators. In Excel, open Developer > Visual Basic to edit or test the macro.
Validate the input and compare it with its integer portion
Use this method when users enter numbers according to the Windows regional settings.
VBA's CDbl conversion uses the system's regional settings. Validate the text first, convert it to a number, and compare it with Int(number). The comparison also works for negative integers.
In Excel, select Developer > Visual Basic, then choose Insert > Module.
Paste this code into the module: Sub CheckInteger() Dim inputText As String Dim number As Double inputText = InputBox("Enter a number:") If Trim$(inputText) = "" Then Exit Sub If Not IsNumeric(inputText) Then MsgBox "Enter a valid number using your Windows regional settings." Exit Sub End If On Error GoTo ConversionError number = CDbl(inputText) MsgBox Int(number) = number Exit Sub ConversionError: MsgBox "The number could not be converted." End Sub
Return to Excel, press Alt+F8, select CheckInteger, and click Run. Enter an integer or a decimal using the separator configured in Windows; the message displays True for an integer and False otherwise.

Align Excel and Windows decimal separator settings
Use this when Excel displays numbers with a different separator from the one VBA expects.
Work with spreadsheets in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and support for common Microsoft Office formats, making it easier to move everyday spreadsheet work between suites. It does not change Excel's VBA or Windows regional settings.

Frequently Asked Questions
How does the VBA macro decide whether a number is an integer?
After converting the input with CDbl, it compares the number with Int(number). If they are equal, the number has no fractional part.
Will the integer check work for negative numbers?
Yes. Int rounds down to an integer, so Int(-2) equals -2, while Int(-2.5) is -3 and does not equal -2.5.
Where can I change Excel's decimal separator?
Open File > Options > Advanced. Under Editing options, clear Use system separators to set custom decimal and thousands separators, or select it to use the Windows settings.
Does changing Excel's separator change how VBA converts input?
Not necessarily. Excel can use custom separators, but VBA's CDbl conversion uses Windows regional settings. Check both settings if input is rejected or interpreted unexpectedly.




