+ Reply to Thread
Results 1 to 7 of 7

VBA to Find Multiple Substrings Within a String

  1. #1
    Registered User
    Join Date
    03-28-2010
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    60

    VBA to Find Multiple Substrings Within a String

    Hello,

    I am trying to figure out how to return multiple values that are adjacent to a series of the same substring. So here is the setup. Say in cell [A1] I have a very long string. Within this string, the following substring will occur an unknown number of times:

    "@baseRate":"499.0"

    This part, "@baseRate": will always be the same, but the "499.0" will vary (both the length of that string and the number of occurences of the string will vary). So I could have a string like this in [A1]:

    ....."@baseRate":"499.0"........."@baseRate":"399.0".........."@baseRate":"99.0" (the periods are other parts of the string that I am not concerned with)

    What I would like to return in [B1]:[D1] would look like the following:

    B1: 499.0 C1: 399.0 D1: 99.0

    The problem I foresee is the actual rate data I am looking for will not have a fixed length and the "@baseRate" could occur one time or it could occur 30+ times.

    Any help is very much appreciated.

    Thank you,

    learning_VBA

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

    Re: VBA to Find Multiple Substrings Within a String

    learning_vba,

    We would have to see examples of the complete strings in column A.

    Even better:

    To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed/changed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

    The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

    To attach your workbook, scroll down and click on the Go Advanced button, then scroll down and click on the Manage Attachments button.
    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.

  3. #3
    Registered User
    Join Date
    03-28-2010
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    60

    Re: VBA to Find Multiple Substrings Within a String

    Stan,

    Ok- I have attached a workbook with the full string. Thank you for your consideration.

    String Example.xlsx

    learning_vba
    Last edited by Leith Ross; 02-04-2014 at 04:09 PM.

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

    Re: VBA to Find Multiple Substrings Within a String

    learning_vba,

    Thanks for the workbook.

    You are only looking for the numeric value that follows @baseRate?


    Detach/open workbook ExtractNumber colA Split onATsymbol_baseRate getnumber - learning_vba - EF986277 - SDG15.xlsm and run the ExtractNumber macro in worksheet Sheet1.

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

    Re: VBA to Find Multiple Substrings Within a String

    Hello

    Here is another method to extract the substrings. This method uses Regular Expressions. A new sheet has been added with a button to run the macro. The macro looks at the data on "Sheet1" and starts filling column "B" on with the rates in cell "A".
    Please Login or Register  to view this content.
    Attached Files Attached Files
    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!)

  6. #6
    Registered User
    Join Date
    03-28-2010
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    60

    Re: VBA to Find Multiple Substrings Within a String

    Thank you Leith- exactly what I was looking for.

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

    Re: VBA to Find Multiple Substrings Within a String

    learning_vba,

    Did you even try my macro?

    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)

Similar Threads

  1. [SOLVED] VBA substrings in string
    By mikejclark in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-28-2013, 08:36 AM
  2. Excel 2007 : Finding substrings in a string
    By kkerr in forum Excel General
    Replies: 4
    Last Post: 06-19-2012, 11:57 AM
  3. Changing multiple substrings within a string
    By RogueArchon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2012, 12:57 PM
  4. Substrings from String
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-23-2010, 05:08 PM
  5. Separtaing A String Into Substrings.
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 07-10-2005, 01:27 AM

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