+ Reply to Thread
Results 1 to 8 of 8

Function for String between 2 characters?

  1. #1
    Registered User
    Join Date
    12-27-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    60

    Function for String between 2 characters?

    Hi all,
    My requirement is to get the string value between two characters(eg : "-").
    Suppose if xxx-yyyyy-zzz is the string in any cell(say A1).I want the result as yyyyy.

    Please Login or Register  to view this content.
    I have the above function.But when I use it as =midtxt(A1) it returns 0.
    Please tell me where I have gone wrong.

    If I use the same logic for a command button then the code works fine.

    Thanks and Regards.
    Last edited by zbor; 12-31-2014 at 05:22 AM. Reason: Code tags

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Function for String between 2 characters?

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  3. #3
    Registered User
    Join Date
    12-27-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Function for String between 2 characters?

    zbor,
    Thanks for the alert.
    My requirement is to get the string value between two characters(eg : "-").
    Suppose if xxx-yyyyy-zzz is the string in any cell(say A1).I want the result as yyyyy.

    Please Login or Register  to view this content.
    I have the above function.But when I use it as =midtxt(A1) it returns 0.
    Please tell me where I have gone wrong.

    If I use the same logic for a command button then the code works fine.

    Thanks and Regards.

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Function for String between 2 characters?

    Hi,

    Please change this line :

    Please Login or Register  to view this content.
    Regards
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Function for String between 2 characters?

    In function you need to retrun result as name of the function:

    Please Login or Register  to view this content.
    But, since your function might fail when having more - in string I suggest you to use this:

    Please Login or Register  to view this content.

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Function for String between 2 characters?

    You can also set separator if you like:

    Please Login or Register  to view this content.
    Use it as:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Function for String between 2 characters?

    And you can also set n-th word to be returned as:
    Please Login or Register  to view this content.
    Where you can use formula as:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This will return 3rd word (ccc).

    Now you have full flexibility of what is separator and what part to return

  8. #8
    Registered User
    Join Date
    12-27-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Function for String between 2 characters?

    Thank you very much zbor and karedog!
    A big thanks for all the answers.

+ 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] Macro to create a new line within a text string if specific characters appear mid-string
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2014, 11:32 AM
  2. [SOLVED] COUNTIF Function for String of more than 255 Characters
    By akbarmajor in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-17-2014, 10:34 AM
  3. [SOLVED] Function to flag non-alphanumeric characters in a text string
    By Sophie.Durrant in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-02-2013, 10:56 AM
  4. [SOLVED] Extract left characters from string with exception of 2 right characters
    By sweetkel23 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-16-2012, 10:45 PM
  5. [SOLVED] Function to trim first 10 characters off a string
    By theletterh in forum Excel General
    Replies: 5
    Last Post: 07-12-2012, 11:43 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