In Excel VBA, IsNumeric and IsNumber both test whether a value can be treated as a number, but they answer slightly different questions. IsNumeric asks "can this expression be converted to a number?", so it returns True for numbers, numeric strings such as "123", and even dates (which Excel stores as serial numbers). IsNumber asks "is this value actually a number data type right now?", so it returns False for text that merely looks like a number. In practice, use IsNumeric to validate user input or text that might hold numbers, and use IsNumber when you need to confirm a variable or cell value is a true numeric type before doing arithmetic. Getting this wrong is the source of most "why does my macro treat "1,234" as a number but crash on concatenation?" surprises.
What You'll Need
- Excel on Windows or Mac with macros enabled (the VBA Editor is not available in Excel for the web).
- A workbook saved as .xlsm or .xlsb if you want to keep your code; .xlsx will discard macros on save.
- Access to the Visual Basic Editor (Alt+F11 on Windows, or Developer tab > Visual Basic; on Mac, Tools > Macro > Visual Basic Editor).
- Macro security set to allow macros, or the workbook placed in a trusted location.
Menu and dialog labels can differ slightly between Excel versions, platforms and regions, so treat the paths below as a guide rather than exact wording.
Step-by-Step
- Open the Visual Basic Editor. Press Alt+F11 on Windows. On Mac, use the Developer tab or the Tools menu (labels vary). If the Developer tab is hidden, enable it via Excel Options > Customize Ribbon and tick Developer.
- Insert a standard module. In the editor, use Insert > Module. This gives you a blank code window where the test procedures will live. Keep test code in its own module so it does not conflict with sheet-level event code.
- Write a simple comparison procedure. Paste a short Sub that feeds several values to both functions and prints the results with
Debug.Printto the Immediate Window (Ctrl+G):
Run it with F5 and read the Immediate Window. You should see True/False for the quoted number, True/True for the real number, and True/False for the comma-formatted string.Sub CompareTests() Debug.Print IsNumeric("123"), IsNumber("123") Debug.Print IsNumeric(123), IsNumber(123) Debug.Print IsNumeric("1,234"), IsNumber("1,234") Debug.Print IsNumeric(""), IsNumber("") Debug.Print IsNumeric(Null), IsNumber(Null) End Sub - Test cell values, not just literals. A cell can hold text or a number even if it looks identical on screen. Read the value first:
PutSub TestCell() Dim v As Variant v = Range("A1").Value Debug.Print TypeName(v), IsNumeric(v), IsNumber(v) End Sub123in A1 formatted as text, then as a real number, and rerun. TheTypeNameoutput (String versus Double/Integer) tells you which one you are dealing with. - Guard arithmetic with the right test. If you are about to add, multiply or compare, protect the operation so text cannot throw a type mismatch:
If IsNumeric(Range("A1").Value) Then total = total + CDbl(Range("A1").Value) Else MsgBox "A1 does not contain a usable number." End IfCDblforces the conversion after the check, so "12.5" stored as text becomes a real number. - Use IsNumber when you must distinguish true numbers from numeric text. For example, to find cells that are genuinely numeric and skip text that only looks numeric:
Green means a true number, yellow means numeric-looking text. This is the clearest way to spot values imported from CSV files that arrived as text.Dim c As Range For Each c In Range("A1:A10") If IsNumber(c.Value) Then c.Interior.Color = vbGreen ElseIf IsNumeric(c.Value) Then c.Interior.Color = vbYellow End If Next c - Handle empty cells and errors deliberately. An empty cell read through
.Valuereturns Empty, whichIsNumerictreats as False (unlike a blank treated as zero in formulas). An error value such as #N/A needs an error check first:If IsError(c.Value) Then ' skip or log ElseIf IsNumeric(c.Value) Then ' safe to convert End If - Test your finished logic on messy data. Include blanks, dates, comma and currency formatted text, values with trailing spaces, negative numbers in parentheses, and a deliberate error value. Change any test that returns True where you expected False, or the reverse, and rerun. Only then wire the code to real ranges.
Common Mistakes
- Assuming IsNumber and IsNumeric are interchangeable. They are not.
IsNumber("5")is False;IsNumeric("5")is True. Pick based on whether you need the type or the value. - Forgetting dates count as numeric.
IsNumericandIsNumberboth return True for a date value because Excel stores dates as serial numbers. If a date must be rejected, check the cell format or useIsDateexplicitly. - Not accounting for locale. Comma versus decimal point separators vary by regional settings, so a string that is numeric on one machine may fail on another. Test on the machines or locales where the workbook will actually run.
- Testing the wrong property.
Range.Textreturns what the cell displays (often with formatting), whileRange.Valuereturns the underlying value. Testing.Textcan make a number look like formatted text. - Skipping the error check. Passing an error value such as #VALUE! into
IsNumericcan raise a runtime error depending on how the value is read, so testIsErrorfirst. - Ignoring Empty. Blank cells return Empty, which is not the same as zero. Confirm this behaves the way your logic expects before looping over large ranges.
Tips
- Use
Debug.Printand the Immediate Window to compare results side by side before committing to one function. - After a successful
IsNumerictest, convert explicitly withCInt,CLngorCDblrather than relying on implicit coercion. - Combine
IsNumericwithTrimto strip stray spaces from pasted text:IsNumeric(Trim(c.Value)). - For whole-column work, read the range into a Variant array and loop in memory instead of testing cell by cell, which is much faster on large sheets.
- Write a small set of known tricky values into your test sheet and keep it in the workbook so you can rerun the check after future edits.
Troubleshooting
Macro will not run. Check that macros are enabled and the workbook is saved in a macro-enabled format. A workbook saved as .xlsx silently drops code when closed.
Unexpected True or False results. Print TypeName next to the result to see whether the value is a String, Double, Date or Empty. That single output usually explains the surprise.
Type mismatch at runtime. Confirm you are testing the value before using it arithmetically, and wrap error values with IsError. If the cell might be text with spaces, trim it first.
Works on your machine, fails elsewhere. Compare regional settings and whether the source data was pasted or imported. Text formats can differ by locale.
If that did not work, rebuild the test in a fresh module with three or four literal values only, confirm the behavior, then reintroduce cell references one at a time until the failure reappears.
Frequently Asked Questions
What is the difference between IsNumeric and IsNumber in VBA?
IsNumeric checks whether a value can be converted to a number, including numeric text and dates. IsNumber checks whether the value is already a numeric data type. A quoted number returns True for IsNumeric and False for IsNumber.
Does IsNumeric return True for dates?
Yes. Dates are stored as serial numbers, so both functions can return True for date values. Use IsDate if you need to identify dates specifically.
Why does IsNumeric return True for a blank cell in some cases?
It depends what you are testing. A truly empty cell read through .Value returns Empty, which is not numeric, but an empty string or a cell displaying nothing after formatting behaves differently. Check the actual value with TypeName before deciding.
Should I use IsNumeric or IsNumber before doing math?
Use IsNumeric if the source could be numeric text, then convert explicitly with CDbl or CLng. Use IsNumber when you only want to accept values that are already numeric.
Can IsNumeric give different answers on different computers?
Yes, because regional settings govern decimal and thousands separators. A string that parses as a number under one locale may not under another.