+ Reply to Thread
Results 1 to 7 of 7

Check if string contains a number

  1. #1
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Bryne, Norway
    MS-Off Ver
    Microsoft Office Excel 2010
    Posts
    230

    Check if string contains a number

    Is there way in Excel VBA to check if a string contains a number, and then return TRUE or FALSE. Numbers can been anywhere in the string. See example below.

    Please Login or Register  to view this content.
    Last edited by mkvassh; 09-25-2009 at 08:47 AM.

  2. #2
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: Check if string contains a number

    Check this out

    http://office.microsoft.com/en-us/ex...549011033.aspx

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Check if string contains a number

    With A1 containing anything.

    Here are two approaches:
    Non-VBA:

    Please Login or Register  to view this content.

    Edited to include this shorter (but slightly less intuitive) alternative:
    Please Login or Register  to view this content.
    Using VBA:


    Please Login or Register  to view this content.
    Usage:
    Please Login or Register  to view this content.
    Does that help?
    Last edited by Ron Coderre; 09-25-2009 at 08:27 AM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: Check if string contains a number

    Alternative

    Please Login or Register  to view this content.

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Check if string contains a number

    Quote Originally Posted by Shijesh Kumar View Post
    Alternative

    Please Login or Register  to view this content.
    I think that would return the count of digits in the referenced cell.

    This would return 1 for cells containing numbers:

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: Check if string contains a number

    yes it will return count of digits..
    so we can modify it as below to return true or false


    Please Login or Register  to view this content.
    One question thousand solution ;-)

  7. #7
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Bryne, Norway
    MS-Off Ver
    Microsoft Office Excel 2010
    Posts
    230

    Re: Check if string contains a number

    It works. Thanks a lot :-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1