+ Reply to Thread
Results 1 to 13 of 13

Extracting Text from a string in a Cell (Excel VBA)

  1. #1
    Registered User
    Join Date
    10-20-2010
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    39

    Exclamation Extracting Text from a string in a Cell (Excel VBA)

    --------------------------------------------------------------------------------

    I have a range of cells that contains data in the form on strings. I need to extract a part of this string and paste it (to the empty cell on the right).

    Range "AV" contains the cells with strings
    I need to extract the data between "0" OR "0:" and till the end of the string in the cell OR till "1"

    Can anyone show me how to do this with a Macro (VBA code) or anyway else ? Thank You

    example :

    (String in a cell)

    shawn012k
    0: james
    pdf: 321
    1:
    pdf:
    2:
    pdf:

    Extracted Data (pasted in the cell to the right):
    james
    pdf: 321
    Last edited by jimmy_nora; 10-27-2010 at 07:17 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Extracting Text from a string in a Cell (Excel VBA)

    jimmy_nora, welcome to the board.

    I am sure you will have the Forum Rules and as such will be aware that if you choose to post the same question in more than one online Forum we ask you disclose all relevant links.

    http://www.mrexcel.com/forum/showthread.php?t=502979

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Extracting Text from a string in a Cell (Excel VBA)

    Incidentally why do you need VBA to do this - would a formula not suffice ?

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-20-2010
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Extracting Text from a string in a Cell (Excel VBA)

    what do you mean by "disclose all relevant links" ?

  5. #5
    Registered User
    Join Date
    10-20-2010
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Extracting Text from a string in a Cell (Excel VBA)

    code does not work !

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Extracting Text from a string in a Cell (Excel VBA)

    You should tell us that you have posted in other forums and provide the link so people do not waste their time answering questions which have already been solved elsewhere.

  7. #7
    Registered User
    Join Date
    10-20-2010
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Extracting Text from a string in a Cell (Excel VBA)

    Is there anyway I can further manipulate this formula to trim only the part between "1" or "1:" and "2:" or "end of cell" ?

    In this case I need to ignore the first 1: because it occurs before the 0:

    example:

    user bio1:
    0: asdasdas
    1: asdasds
    2:
    3: asdas

    required data:
    asdasds

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Extracting Text from a string in a Cell (Excel VBA)

    jimmy_nora please at least detail the fact that you have updated your thread at MrExcel with the same - granted it remains the same cross post (detailed by me) but it's not clear from your post you have done this.

  9. #9
    Registered User
    Join Date
    09-14-2010
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Extracting Text from a string in a Cell (Excel VBA)

    hi i think this will be helpful.
    =LEFT(RIGHT(B4,LEN(B4)-FIND("1",B4)),FIND("0",RIGHT(B4,LEN(B4)-FIND("1",B4)))-1)

    this formula gives you the string between 0 and 1.
    you can change the character in place of 0 or 1.

  10. #10
    Registered User
    Join Date
    10-20-2010
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Extracting Text from a string in a Cell (Excel VBA)

    Quote Originally Posted by ashwanik_aggarwal View Post
    hi i think this will be helpful.
    =LEFT(RIGHT(B4,LEN(B4)-FIND("1",B4)),FIND("0",RIGHT(B4,LEN(B4)-FIND("1",B4)))-1)

    this formula gives you the string between 0 and 1.
    you can change the character in place of 0 or 1.
    your code doesn't work for me

  11. #11
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Extracting Text from a string in a Cell (Excel VBA)

    Quote Originally Posted by jimmy_nora View Post
    In this case I need to ignore the first 1: because it occurs before the 0:

    example:

    user bio1:
    0: asdasdas
    1: asdasds
    2:
    3: asdas

    required data:
    asdasds
    The formula provided previously already returns "asdasds".

    If you can not replicate I would suggest you post a sample file to better illustrate the problems you are experiencing.

    edit: ignore that - I see what you mean now
    Last edited by DonkeyOte; 10-22-2010 at 05:14 AM.

  12. #12
    Registered User
    Join Date
    09-14-2010
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Extracting Text from a string in a Cell (Excel VBA)

    =LEFT(RIGHT(B4,LEN(B4)-FIND("1",B4)),FIND("0",RIGHT(B4,LEN(B4)-FIND("1",B4)))-1)

    Paste this formula in cell C4.
    and Enter the string into B4.
    It will work definetly

  13. #13
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Extracting Text from a string in a Cell (Excel VBA)

    @jimmy_nora

    I have posted an update to your thread at MrExcel.com with screenshot of output

    http://www.mrexcel.com/forum/showthread.php?t=502979

    I have added a file here.
    Attached Files Attached Files
    Last edited by DonkeyOte; 10-22-2010 at 05:32 AM.

+ 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