+ Reply to Thread
Results 1 to 5 of 5

help with pulling number from a string

  1. #1
    Registered User
    Join Date
    12-10-2008
    Location
    Aberdeen
    MS-Off Ver
    MS365 VER 2308
    Posts
    79

    help with pulling number from a string

    Hi there,
    I need help because my solutions aren't working - at least not always.

    I have a vba function called "extract(s as string) as string", which is supposed to find a 10-digit number starting with "45", "46" or "90" anywhere within a string, and return it if found, otherwise return empty string.

    I'm finding that if 45, 46 or 90 appear elsewhere in the string, then it will also return that, and miss the 10-digit number - which causes problems.

    Whats the best way to return the 10-digit number in the below string cases?

    "Hello this is my number 4534567890"
    "4534567890 is my number"
    "the number 45 appears in 4534567890"
    "the number 4534567890 includes the digits 45 at the start"
    "the number 4534567890 also includes 90 at the end"
    "there are sometimes no spaces in front of4534567890"
    "sometimes 4534567890 comes before 4509876543" -in which case I need only the first instance - or an array of matches, but that's maybe getting ahead of ourselves.
    "there's no match in 900046045 as it's not 10 digits long"

    Is there a regex statement that I could use (and if so, how)? Not just to detect the presence of a matching number, but to actually return it.

    many thanks
    Guy
    Last edited by bluphoto; 03-16-2023 at 12:48 PM.

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,061

    Re: help with pulling number from a string

    Does this work for you?

    Please Login or Register  to view this content.

  3. #3
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: help with pulling number from a string

    Maybe :
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  4. #4
    Registered User
    Join Date
    12-10-2008
    Location
    Aberdeen
    MS-Off Ver
    MS365 VER 2308
    Posts
    79

    Re: help with pulling number from a string

    Wow,thanks for that guys. Really appreciate this.

  5. #5
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: help with pulling number from a string

    You are welcome, thanks for rep.points given, and don't forget to mark this thread as solved.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Pulling number values from text string
    By coeo1st in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-06-2022, 04:30 AM
  2. [SOLVED] Pulling certain criteria from a string of text and match to a pallet number
    By pmw19800 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-26-2021, 02:21 PM
  3. Replies: 2
    Last Post: 01-05-2018, 12:31 AM
  4. [SOLVED] Pulling Number from Text String
    By sbeatty in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-03-2017, 12:51 PM
  5. [SOLVED] pulling out 12 digit number from an alphanumeric string
    By susan doyle in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-19-2013, 08:49 AM
  6. Pulling only the number out of a string
    By bconner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-19-2008, 03:32 PM
  7. [SOLVED] Pulling apart a string
    By Kevin O'Neill in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-06-2006, 01:32 PM

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