+ Reply to Thread
Results 1 to 11 of 11

VBA substrings in string

  1. #1
    Registered User
    Join Date
    06-11-2012
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    VBA substrings in string

    Hi all. I have searched high and low but I can't get to the bottom of this one. Hopefully someone here can point me in the general direction?

    I have strings that could look like "N01N03N10N35" or "N 1N 7N12" or "N1N6N20"

    Each substring will always start with a capital "N" followed by either two numbers, a space and a number, or no space and a number/s.

    I need to do the following operations on this string:
    1. Extract each substring text from the string
    2. Find the start position of each substring (possibly using instr?)
    3. Get the length of each substring

    I have tried instr but I don't think it is possible to use a wildcard. I have had some success with split but can only extract the numbers following.

    This my attempt at extracting the substring:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Any help is hugely appreciated!

    Thanks
    Mike

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA substrings in string

    Please Login or Register  to view this content.
    ?

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA substrings in string

    Try
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-11-2012
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA substrings in string

    Can't thank you both enough! Both solutions are exactly what I was looking for...

  5. #5
    Registered User
    Join Date
    06-11-2012
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA substrings in string

    Quote Originally Posted by jindon View Post
    Try
    Please Login or Register  to view this content.
    Hi jindon,

    I like this code but I get an error "Constant expression required" when I integrate to my code. The string named NoteText is a variable not a constant. Is there a way I can adapt the code for this?

    Thanks
    Mike

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA substrings in string

    Need to see full code.

  7. #7
    Registered User
    Join Date
    06-11-2012
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA substrings in string

    Quote Originally Posted by jindon View Post
    Need to see full code.
    Thank you for the reply, jindon. I think I have just figured it out:

    Please Login or Register  to view this content.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA substrings in string

    Please Login or Register  to view this content.
    What's this? It has no such method.

  9. #9
    Registered User
    Join Date
    06-11-2012
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA substrings in string

    Quote Originally Posted by jindon View Post
    Please Login or Register  to view this content.
    What's this? It has no such method.
    In your code I thought "test" referenced the name of the sub, so I change it to the name of my sub. The code works with either "test" or TableTest" though???

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA substrings in string

    No, it's a test method for Regular Expression.

    Is must be
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-11-2012
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA substrings in string

    I've changed my code and will learn how the expression works.
    Your help is greatly appreciated.

+ 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. Excel 2007 : Finding substrings in a string
    By kkerr in forum Excel General
    Replies: 4
    Last Post: 06-19-2012, 11:57 AM
  2. Changing multiple substrings within a string
    By RogueArchon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2012, 12:57 PM
  3. Substrings from String
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-23-2010, 05:08 PM
  4. sum wrt substrings!
    By via135 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-26-2006, 02:06 PM
  5. Separtaing A String Into Substrings.
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 07-10-2005, 01:27 AM

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