+ Reply to Thread
Results 1 to 3 of 3

VBA code not returning correct string using MID and InStr

  1. #1
    Registered User
    Join Date
    11-26-2011
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    23

    Unhappy VBA code not returning correct string using MID and InStr

    i cannot get this to return the string I want.
    Cell F1 contains text: Ship-To: (23) DAVIDSON FAMILY HEALTH SCIENCE
    My desire: return to cell b3 the text beginning 2 places after the position of the close parenthesis
    In excel spreadsheet, this formula returns the correct text =MID(F1,FIND(")",F1)+2,LEN(F1)-FIND(")",F1))
    The desired string to return would be: DAVIDSON FAMILY HEALTH SCIENCE
    What I am getting returned to cell B3 is: hip-To: (23) DAVIDSON FAMILY HEALTH SCIENCE
    Why is only the first character of the text in F1 being stripped off?

    The position of the Close Parenthesis and the length of the string in F1 will vary with each data set, so I can't just hard code in a certain number of characters from the right end of the string in F1.

    Any help would be appreciated, I'm sure I am just missing something simple...

    Please Login or Register  to view this content.

  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,258

    Re: VBA code not returning correct string using MID and InStr

    Hello kramtelbuab,

    You are on the right track. You need to save where the closing parenthesis was found.
    Please Login or Register  to view this content.
    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-26-2011
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: VBA code not returning correct string using MID and InStr

    I copied over your changes Dim n and initializing it. Now I am getting the complete text from cell F1 loaded into cell B3. I tracked through the Locals window and see that the value of n is never changing from Zero. I will try relooking at this tomorrow, getting late enough tonight my eyes are fuzzy. Thanks for your help!

+ 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