+ Reply to Thread
Results 1 to 8 of 8

Return text with regex find function

  1. #1
    Registered User
    Join Date
    11-11-2008
    Location
    Syracuse NY
    MS-Off Ver
    2007
    Posts
    90

    Return text with regex find function

    In VBA , I'm trying to return the result of a regex find to my own sub with the following function. The problem is, I can't figure out what it's returning, or how to get it to return the actual text of the match. I also need to test if there is or isn't a match.

    The function, from this page ( http://www.tmehta.com/regexp/add_code.htm ) is reproduced here for convenience:

    Please Login or Register  to view this content.
    This function seems to allow for the possibility of finding more than one match at a time, which is not what I want.

    Here is an example of how I'm trying to use it. TwoWaySplitNum is a string variable.

    Please Login or Register  to view this content.
    There's also a RegExpSubstitute function on that page if you're interested.
    Last edited by jrussell; 05-07-2010 at 08:29 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Return text with regex find function

    Hello jrussell,

    Is this a question or a comment? You can replace substrings with RegExp. You need to provide the data you want parsed. RegExp are rather complex and the more data you provide the better.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-11-2008
    Location
    Syracuse NY
    MS-Off Ver
    2007
    Posts
    90

    Re: Return text with regex find function

    Here are some examples of data I need to parse. It's percentage splits among salespeople that I need to find. See the attached workbook for more in-depth examples. If the 'desired result' columns error out on your computer, see the 'desired result text' columns.

    April Totowa/Adam Zeller 50/50
    75/25 Robin Heller/ Matthew Krason
    Mike Viera/ Mike Stein 50/50 eff: 08/01/09 E&M
    Abe Smith/John Franks/Lisa Lowe 60/20/20

    It works fine if I just enter the formulas on a worksheet. I'm just having trouble using the RegExpFind function in a macro.

    I have the logic worked out to first look for a three-way split, and if that fails, to look for a two-way split, and I can work out how to match the patterns with regex. I don't need help with that.

    I need help figuring out in VBA how to return actual matching text if there is any, and how to handle it if there isn't any.

    Here is the half-written macro where I'm trying to use this. If you copy this and the RegExpFind into a module and run it on the attached file "real sheet for upload" you'll be able to step through and follow along in the locals window. Hope this helps.


    Please Login or Register  to view this content.
    Last edited by jrussell; 04-23-2010 at 02:46 PM.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Return text with regex find function

    Hello jrussell,

    Sorry for the delay. I had some other unexpected business to attend to today. Here is the macro. It will size the range automatically and put the parsed data into the cells to the right of the raw (unparsed) data. This example starts at "A2" on "Sheet1". The parsed data is placed in columns "B:C". You can change this for your needs.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-11-2008
    Location
    Syracuse NY
    MS-Off Ver
    2007
    Posts
    90

    Re: Return text with regex find function

    Leith, thanks for this. It might take me some time, but I will see what I can do with it.

  6. #6
    Registered User
    Join Date
    11-11-2008
    Location
    Syracuse NY
    MS-Off Ver
    2007
    Posts
    90

    Re: Return text with regex find function

    Edit: Got past that step, still working on it though...
    Last edited by jrussell; 04-29-2010 at 10:32 AM.

  7. #7
    Registered User
    Join Date
    11-11-2008
    Location
    Syracuse NY
    MS-Off Ver
    2007
    Posts
    90

    Re: Return text with regex find function

    Hi Leith, just a note to let you know that I got this to do what I needed. I had to add a bunch of other stuff, but it works great now!

    Please Login or Register  to view this content.
    Text too long... continued in next post.

  8. #8
    Registered User
    Join Date
    11-11-2008
    Location
    Syracuse NY
    MS-Off Ver
    2007
    Posts
    90

    Re: Return text with regex find function

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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