+ Reply to Thread
Results 1 to 12 of 12

Trying to learn how to use CreateObject("VBScript.RegExp")

  1. #1
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Trying to learn how to use CreateObject("VBScript.RegExp")

    Team,

    I am trying to learn how to create code and patterns for CreateObject("VBScript.RegExp").

    With the following information in column A, beginning in cell A1:
    GRP10-0137-
    GRP10-0212-PO10-0213
    20032010 - MAJU TERUS-PO10-0088-GRP10-0071
    20032010 - MAJU MUNDUR-PO10-0087-A-GRP10-0071


    Using CreateObject("VBScript.RegExp"), what would the Function and Pattern be to extract the bold PO infomation into column B, or return a 0 (zero)?
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    I'm not very good at RegEx I'm afraid but whilst the others come up with something perhaps the below might help get the cogs turning...

    Please Login or Register  to view this content.
    above assumes you're looking for "PO##-####-?" where -? is variable (and ? is 1 char in length [if exists])

    Assuming you don't want the closing hyphen (in case of -A-) you might want to check the matching output and adjust accordingly (ie remove if last char is hyphen)

    EDIT:

    I failed to notice you were looking for more than just the pattern....

    Please Login or Register  to view this content.
    The above is rather generic (ie not specific to this thread) - ie pass the pattern to the UDF rather than storing the pattern within the UDF.

    Please Login or Register  to view this content.
    of course the pattern need not be a constant (ie reference to another cell) and you have additional optional parameters to extract particular instances / affect Case sensitivity etc...
    Last edited by DonkeyOte; 09-04-2010 at 03:37 AM.

  3. #3
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    Hi stanleydgromjr
    This is the same as DO's but with a different error handler
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    Quote Originally Posted by pike View Post
    Hi stanleydgromjr
    This is the same as DO's but with a different error handler
    Not quite the same ... there are a few other variables in the first Function (hence the additional lines of code)

    The handler in the first accounts for possibility that there may be a match but that the specific match being returned exceeds the number of matches found.
    (ie interested in third match but only two matches found)

  5. #5
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    true ,
    just wanted to post the pattern . it did take me a while to write
    Its near imposible to stump the DO

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    Quote Originally Posted by pike
    Its near imposible to stump the DO
    far from it unfortunately... ... I also suspect there's a much better pattern.

  7. #7
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    DonkeyOte,

    With a slight modification it works.

    Thank you so very much.

    What a great site for learning.


    Please Login or Register  to view this content.

    Can you have in a Pattern that would exclude, or stop at, some string characters like -GRP?

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    Quote Originally Posted by sd
    an you have in a Pattern that would exclude, or stop at, some string characters like -GRP?
    Undoubtedly but could you clarify requirements by means of example(s) ?

    For info. on Reg Exp: http://www.regular-expressions.info/

    To reiterate I'm no expert and muddle my way through - plenty here are however.

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    Did you consider this alternative (although it will not teach you using Reg.Exp).
    Please Login or Register  to view this content.

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    for info. this thread has extensions elsewhere which may be of interest
    (at least to those who of us who like to see clever pattern constructs - c/o Pedro at MrE)

    http://www.mrexcel.com/forum/showthread.php?t=492837

  11. #11
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    pgc01, DonkeyOte,

    Sorry for not cross posting. I was trying to find a solution for penambangliar in an area that I am trying to learn about, VBScript.RegExp.

    MrExcel and Excel Forum are by far the two best sites I have come accross where I have learned so much to improve my VBA skills.

    Thank you, thank you so much.

  12. #12
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Trying to learn how to use CreateObject("VBScript.RegExp")

    pgc01, DonkeyOte,

    For the data posted in my request, here is my latest solution, per the help of pgc01, and DonkeyOte.


    Please Login or Register  to view this content.
    Last edited by stanleydgromjr; 09-04-2010 at 08:10 PM.

+ 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