+ Reply to Thread
Results 1 to 16 of 16

Retrieving portion of cell value

  1. #1
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Retrieving portion of cell value

    Hi,

    I'm cleaning up some data. I have some fields like this:

    LSKFJ(38) (513 Rating)
    SDFSDFSDFSD(2352) (71 Rating)
    FS(37) (53 Rating)

    I want to remove the rating portion from this column and place it into another column. So the first column would look like this:

    LSKFJ(38)
    SDFSDFSDFSD(2352)
    FS(37)

    And the second column looks like this:

    (513 Rating)
    (71 Rating)
    (53 Rating)

    I've played around with the RIGHT() and FIND() functions, but I haven't managed to achieve what I'm looking for.

    Any help on this is greatly appreciated.
    Last edited by hk106; 12-22-2011 at 10:14 AM. Reason: Altering the sample data to better demonstrate the problem.

  2. #2
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Retrieving portion of cell value

    Assume the original text is in A1 and then exploit the ") (" occurence. Do you have a ") (" in each cell?

    This gets the left hand part:
    =LEFT(A1,FIND(") (",A1,1))

    And this gets the right hand part:
    =RIGHT(A1,LEN(A1)-1-FIND(") (",A1,1))

    ---EDIT---
    Forgot the minus one there in my original post...
    Last edited by GeneralDisarray; 12-21-2011 at 02:08 PM.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,268

    Re: Retrieving portion of cell value

    Hi hk106,

    If all your ratings are two digit numbers you can grab them using
    =Right(A1,11)
    Then the left side becomes
    =Left(A1,Len(A1)-11)
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Retrieving portion of cell value

    dude your going to include the space with that Left function (hence the minus one in my post) or just subtract 12 in the Left() function case

  5. #5
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Retrieving portion of cell value

    I apologize for not clarifying: the rating are not always two digits. Eye-balling the data, it looks like there is almost always the ") (" pattern.

    Anyway, trying the =LEFT(H2,FIND(") (",H2,1)) formula gives me an error. "A value used in the formula is of the wrong data type."

  6. #6
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Retrieving portion of cell value

    can you upload an example workbook? Do you still get the error when you replace find (") (",H2,1) with a number?

  7. #7
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Retrieving portion of cell value

    Using a number in place of find() returns part of the string (not an error message).

    Does that help? Otherwise, I'll prepare a sample workbook.

    Thanks.

  8. #8
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Retrieving portion of cell value

    i was thinking there may be something "strange" about the space character - non-breaking space issue?

    I'm not sure what's up, but thought an example book would help out.

    Can you find and replace all the ") (" with ")(" (no space)?

  9. #9
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Retrieving portion of cell value

    Assuming text in cell C5 perhaps you could split it using

    =MID(C5,1,FIND(" ",C5)) for the first part and

    =TRIM(MID(C5,FIND(" ",C5),LEN(C5))) for rating part.


    Alf
    Last edited by Alf; 12-21-2011 at 04:19 PM.

  10. #10
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,268

    Re: Retrieving portion of cell value

    @GeneralDisarray,
    I've seen many of these data conversions where the assumed space character is really character 160. You really need hk106 to attach an example file to see if the space is really a space. If it isn't a space then =Trim(Left(A1,Len(A1)-11)) won't work either.

    Try the attached for Rating numbers of up-to 4 digits in length.
    Attached Files Attached Files

  11. #11
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    540

    Re: Retrieving portion of cell value

    Could "text to columns" work here using a space as the delimiter?
    Excel 365 user. To unblock a downloaded macro-enabled workbook, go to your "Downloads" folder > right click on the workbook name > click 'Properties' > check the 'Unblock' checkbox. You can now open the workbook.

  12. #12
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Retrieving portion of cell value

    Ignore the attached sample. I'll prepare another one.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Retrieving portion of cell value

    After copying and pasting the data into another file, I am now getting the formula to work for some of the records, but I'm realizing many records don't contain the ") (" pattern. What I'm trying to extract is the (513 Rating) portion at the end (this is in every record). I'd like to use a regular expression such as "(*Rating)" (wouldn't work perfectly, but at least it would be a starting point), but I receive the error for every record when I do this.

  14. #14
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    365
    Posts
    2,243

    Re: Retrieving portion of cell value

    Try this,

    C2,

    ="("&TRIM(RIGHT(SUBSTITUTE(A2,"(",REPT(" ",LEN(A2))),LEN(A2)))

    B2,

    =SUBSTITUTE(A2,C2,"")

    Copy down.
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  15. #15
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Retrieving portion of cell value

    @marvinP, thank you for the info, i couldn't remember what to look up on that issue.

    @hk106, Try this...: =RIGHT(A1,LEN(A1)-FIND("(",A1,2)+1)

    By setting the start value on the find function to 2, you will skip the first character (which is the first open parenthesis) and find the 2nd occurence.

    IF for some reason some of your cells don't start with that character you could use the more general function below to find the second "(".
    =RIGHT(A1,LEN(A1)-FIND("(",A1,1+FIND("(",A1,1))+1)

    THis should work as long as the data column has the general structure, (something #) (Rating #), where the rating is inside the second set of parenthesis. Anyway, seems to work just find on my test cases.
    Last edited by GeneralDisarray; 12-21-2011 at 07:03 PM.

  16. #16
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Retrieving portion of cell value

    Thank you for the responses everyone. The formulas you've provided addressed most of the fields; due to inconsistencies in the structure of the records, I had to update some of them manually.

+ 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