Results 1 to 5 of 5

VBA Test if cell content is a number

This is a discussion on VBA Test if cell content is a number within the Excel Questions forums, part of the Question Forums category; Hi, How can I test or check, in VBA code, whether the content of a given cell is a number? ...

  1. #1
    Board Regular
    Join Date
    Dec 2007
    Location
    Amsterdam
    Posts
    63

    Default VBA Test if cell content is a number

    Hi,

    How can I test or check, in VBA code, whether the content of a given cell is a number?

    Thanks.

  2. #2
    Board Regular dave3009's Avatar
    Join Date
    Jun 2006
    Location
    Glasgow, Scotland
    Posts
    6,292

    Default Re: VBA Test if cell content is a number

    Take a look at the IsNumeric help in the VBA editor

    KR


    Dave
    Please state your version of Excel, I use Excel 2007 on Win 7.
    Back up all data before testing VBA codes, and please use [code] tags.
    davehouston.co.uk/

  3. #3
    Board Regular
    Join Date
    Apr 2006
    Posts
    353

    Default Re: VBA Test if cell content is a number

    Maybe

    Code:
    Sub TestForNumber()
    Dim Rng As Range
    Set Rng = Range("A1")
        If IsNumeric(Rng) Then
            MsgBox Rng.Address(False, False) & " is a Number"
        Else
            MsgBox Rng.Address(False, False) & " is not a Number"
        End If
    End Sub
    VBA Noob

  4. #4
    Board Regular
    Join Date
    Dec 2007
    Location
    Amsterdam
    Posts
    63

    Default Re: VBA Test if cell content is a number

    Thanx!

  5. #5
    MrExcel MVP
    Moderator
    Scott Huish's Avatar
    Join Date
    Mar 2004
    Location
    Oregon
    Posts
    17,080

    Default Re: VBA Test if cell content is a number

    IsNumeric will return TRUE for empty cells, because empty cells can be evaluated as the number 0:

    Code:
    Sub test()
    Dim c As Range, msg As String
    msg = " is not a number"
    Set c = Range("A1")
    If IsNumeric(c) And c <> "" Then msg = " is a number"
    MsgBox c.Address(0, 0) & msg
    End Sub
    Office 2007/2010

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com