EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 120+ Courses All in One Bundle
  • Login
Home VBA VBA Resources VBA Math & Trig Functions VBA IsNumeric
Secondary Sidebar
VBA Math & Trig Functions
  • VBA Math & Trig
    • VBA Random Number
    • VBA Number Format
    • VBA Integer
    • VBA MOD
    • VBA IsNumeric
    • VBA Round
    • VBA INT
    • VBA RoundUp
    • VBA Intersect
    • VBA Randomize
    • VBA Square Root

VBA IsNumeric

By Ashwani JaiswalAshwani Jaiswal

VBA IsNumeric

VBA IsNumeric

IsNumber an excel function is used for identifying whether the cell content is a number or not. A numeric value can be a whole value or integer. An IsNumeric function can also be performed in VBA as well. In VBA this is available with the name “IsNumeric“. IsNumeric works in the same manner as IsNumber does. It analyzes the cell value and returns the answer whether it is a number or not.

IsNumeric considers only Boolean, which only gives result in the form of TRUE and FALSE.

Syntax of IsNumeric in Excel VBA

VBA IsNumeric has the following syntax in VBA:

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax of IsNumeric

How to Use Excel VBA IsNumeric?

We will learn how to use a VBA IsNumeric with few examples in excel.

You can download this VBA IsNumeric Excel Template here – VBA IsNumeric Excel Template

VBA IsNumeric – Example #1

Let’s see an easy example where we will select a cell with any content and in a separate cell, we will see whether cell content is a Number or Not.

All in One Financial Analyst Bundle(250+ Courses, 40+ Projects)
Financial ModelingInvestment BankingUS GAAPCFA-Level 1 & 2
Equity ResearchM & A ModelingPrivate Equity ModelingForex Trading
Price
View Courses
250+ Online Courses | 40+ Projects | 1000+ Hours | Verifiable Certificates | Lifetime Access
4.9 (86,580 ratings)

Step 1: For this open, a new module in the VBA window under the Insert menu tab as shown below.

VBA IsNumeric Example 1-1

Step 2: Write a Subcategory in the name of a performed function or in any other name as shown below.

Code:

Sub VBA_Isnumeric1()

End Sub

VBA IsNumeric Example 1-2

Step 3: Now we will use the If-Else loop for this complete condition. For this open and close If bracket as shown below.

Code:

Sub VBA_Isnumeric1()

If

End If

End Sub

VBA IsNumeric Example 1-3

Step 4: Now in If write and select IsNumeric function and select any Range cell from where we will analyze the content. Here we have selected cell A1 as TRUE.

Code:

Sub VBA_Isnumeric1()

If IsNumeric(Range("A1")) = True Then

End If

End Sub

VBA IsNumeric Example 1-4

Step 5: If cell value at cell A1 is TRUE it means it is a number then we can choose writing any sentence in cell B1 which will say “It is a Number” or put any text as per your choice.

Code:

Sub VBA_Isnumeric1()

If IsNumeric(Range("A1")) = True Then
    Range("B1") = "It is a Number"
End If

End Sub

VBA IsNumeric Example 1-5

Step 6: Now in Else line of code consider writing what we could see when IF condition doesn’t work. We are selecting cell B1 where we will see the output statement of cell A1 as “It is not a Number” as shown below.

Code:

Sub VBA_Isnumeric1()

If IsNumeric(Range("A1")) = True Then
    Range("B1") = "It is a Number"
Else
    Range("B1") = "It is not a Number"
End If

End Sub

VBA IsNumeric Example 1-6

Step 7: Once done then compile and run the complete code. As we can see in the below screenshot for the cell content A1 we got the statement as “It is a Number” in cell B1.

Result of Example 1-7

Step 8: Now let’s replace 10 in cell A1 with a text like “Test” and see what we get.

VBA IsNumeric Example 1-8

Step 9: Now again run the complete code.

Result of Example 1-9

As we can see in the above screenshot, for the cell content A1 we got the statement as “It is not a number” for content “Test” which means cell A1 doesn’t have a number in it.

VBA IsNumeric – Example #2

There is another way to add IsNumeric. By far we all know that Boolean function is used for TRUE/ FALSE on the basis of what we feed and define the condition. Here we will use Boolean to calculate IsNumeric for any content of the cell.

Step 1: Write a Subcategory in the name of a performed function as shown below.

Code:

Sub VBA_IsNumeric2()

End Sub

VBA IsNumeric Example 2-1

Step 2: Now define a dimension “DIM” as A and assign it to Double. We can assign it as Integer or Long too. But that would only consider whole numbers and long text/numbers. Double is used where we are expecting to get numbers in decimal forms.

Code:

Sub VBA_IsNumeric2()

  Dim A As Double

End Sub

VBA IsNumeric Example 2-2

Step 3: Now define one more dimension “DIM” as X. And assign it as Boolean. We can consider any word, name or alphabet for defining dimensions in VBA.

Code:

Sub VBA_IsNumeric2()

  Dim A As Double
  Dim X As Boolean

End Sub

VBA IsNumeric Example 2-3

Step 4: Now for Dim A double, first assign the value as 10 which is a whole number.

Code:

Sub VBA_IsNumeric2()

  Dim A As Double
  Dim X As Boolean

  A = 10

End Sub

VBA IsNumeric Example 2-4

Step 5: Now for Boolean X, use IsNumeric function and assign defined Double A into the brackets of IsNumeric. By doing this IsNumeric will fetch the value stored in Dim A and analyze whether that value is a number or not.

Code:

Sub VBA_IsNumeric2()

  Dim A As Double
  Dim X As Boolean

  A = 10
  X = IsNumeric(A)

End Sub

VBA IsNumeric Example 2-5

Step 6: To get the answer of an analysis done by Isnumeric, we will assign it to a message box where we will see the result.

Code:

Sub VBA_IsNumeric2()

  Dim A As Double
  Dim X As Boolean

  A = 10
  X = IsNumeric(A)

MsgBox "The expression(10) is numeric or not : " & X, vbInformation, "VBA IsNumeric Function"

End Sub

VBA IsNumeric Example 2-6

Step 7: Once done compile and run the code.

Result of Example 2-7

As we can see a pop-up dialog box in the above image, the expression(10) is a TRUE numeric value.

Step 8: Now let’s change the value and put some decimal value in IsNumeric as shown below and see what output we get. Here we have to change the value of A as 10.12 and updated the message box with expression(10.12).

Code:

Sub VBA_IsNumeric2()

  Dim A As Double
  Dim X As Boolean

  A = 10.12
  X = IsNumeric(A)

MsgBox "The expression(10.12) is numeric or not : " & X, vbInformation, "VBA IsNumeric Function"

End Sub

VBA IsNumeric Example 2-8

Step 9: Now again compile and run the complete code.

Result of Example 2-9

We will again get TRUE for the value 10.12 which is a decimal value.

Step 10: Now let’s see if the current defined syntax of IsNumeric still works for other than numbers or not. For this, we need to change the Dim A as String which means we will be entering the Text value here. And change value entered for A. We have considered sample value as “ABC”. Make all necessary changes in related fields where we can place text instead of numbers and keep the rest of the things as it is.

Code:

Sub VBA_IsNumeric2()

  Dim A As String
  Dim X As Boolean

  A = ABC
  X = IsNumeric(A)

MsgBox "The expression('ABC') is numeric or not : " & X, vbInformation, "VBA IsNumeric Function"

End Sub

Example 2-10

Step 11: After that compile and run the complete code.

Result of Example 2-11

Pros of Excel VBA IsNumeric

  • It is so easy to apply IsNumeric in VBA. It is as simple as applying Isnumber through insert function.
  • IsNumeric and IsNumber give the same result.

Cons of Excel VBA IsNumeric

  • Applying example-2 where we need to insert text makes the simple process lengthy.

Things To Remember

  • Recording a macro is also a way to perform IsNumeric function in VBA.
  • Save the file in Macro-Enabled Excel, This is the best way to avoid losing written code.
  • Best way to avoid any error while running the code is to first compile the complete code before we fix it as final.
  • Assigning the created code into a button is also a way to perform created macro quickly, this saves time.
  • If you are applying IsNumeric by example-2 method then remember to keep text in the single quote (‘Text’) otherwise it will give an error.
  • As IsNumeric in VBA is used, in excel it used in the name of IsNumber.

Recommended Articles

This has been a guide to VBA IsNumeric. Here we discussed how to use Excel VBA IsNumeric along with practical examples and downloadable excel template. You can also go through our other suggested articles –

  1. VBA Dim
  2. VBA RGB
  3. VBA IFError
  4. VBA Login
3 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign In
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Excel Charts
  • Excel Tips
  • All Tutorials
Certification Courses
  • All Courses
  • Excel VBA Course - All in One Bundle
  • VBA Course
  • Excel Data Analysis Course
  • Excel for Marketing Course
  • Excel for Finance Course
  • Excel for HR Training

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more