+ Reply to Thread
Results 1 to 10 of 10

Extracting lines starting with a certain number in a cell.

  1. #1
    Registered User
    Join Date
    04-28-2022
    Location
    Oslo, Norway
    MS-Off Ver
    MS Office Professional Plus 2019
    Posts
    4

    Extracting lines starting with a certain number in a cell.

    Hello.

    I have an issue that i need some help sorting out

    I have several excel documents containing cells with many lines within one cell. each of these lines have a special formatting. like this:

    1 text 123456.654321: Some text {some link}
    987654.456789: some more text {another link}
    987654.456789: some more text {another link}
    222222.111111: some more text {another link}
    222222.111111: some more text {another link}
    123456.654321: Some text {some link}

    So what i want to do is to extract all lines starting with 222222. Or remove all that start with something different than 222222.
    I have managed to extract the first line in the cell using MID formula, but i am struggling with getting all of them since there are many cases within one cell.
    I have used this formula:
    =MID(C2; FIND("248848";C2);LEN(LEFT(C2;(FIND("}";C2;1)-11))))


    Thanks in advance.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,263

    Re: Extracting lines starting with a certain number in a cell.

    Welcome to the forum.

    Your sample does not copy correctly into Excel - could you please attach a sample workbook. Instructions at the top of the page.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,959

    Re: Extracting lines starting with a certain number in a cell.

    Does this do what you had wanted?


    =FILTERXML("<A><B>"&SUBSTITUTE(B2,CHAR(10),"</B><B>")&"</B></A>","//B[starts-with(., '222222')]")
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  4. #4
    Registered User
    Join Date
    04-28-2022
    Location
    Oslo, Norway
    MS-Off Ver
    MS Office Professional Plus 2019
    Posts
    4

    Re: Extracting lines starting with a certain number in a cell.

    Here is an example file. C2 is the information I need to extract from. G2 is my own attempt and H2 is how i would like the result to be. Also, the text in each line may differ.

    Thanks in advance.
    Attached Files Attached Files
    Last edited by Carsten211; 04-28-2022 at 06:28 AM.

  5. #5
    Registered User
    Join Date
    04-28-2022
    Location
    Oslo, Norway
    MS-Off Ver
    MS Office Professional Plus 2019
    Posts
    4

    Re: Extracting lines starting with a certain number in a cell.

    Glenn Kennedy
    Thanks for the response.
    Not fully, it seems to only extract the first out of the two. i need it to extract both and result in the same cell (same kind of format as originally minus the ones not starting with 222222)

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,959

    Re: Extracting lines starting with a certain number in a cell.

    1. Did it work in my file?

    2. Is there any reason why you are using the obsolete .xls file extension (it wnt out in 2007). I resaved it as .xlsx.

    3. You did not say that you wanted the results concatenated back into a single cell.

    4. It works for me.. as apated to concatenate the results.


    =TEXTJOIN(CHAR(10),,FILTERXML("<A><B>"&SUBSTITUTE(C2,CHAR(10),"</B><B>")&"</B></A>","//B[starts-with(., '248848')]"))
    Attached Files Attached Files

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,263

    Re: Extracting lines starting with a certain number in a cell.

    Does it need entering with CSE for Excel 2019?

  8. #8
    Registered User
    Join Date
    04-28-2022
    Location
    Oslo, Norway
    MS-Off Ver
    MS Office Professional Plus 2019
    Posts
    4

    Re: Extracting lines starting with a certain number in a cell.

    I got it working now! :D Was not familiar with the CSE formulas. No good reason to not use XLSX. Just a bad choice of extension when doing my export from database
    Thank you so much! you really saved me a lot of time and hassle :D

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,959

    Re: Extracting lines starting with a certain number in a cell.

    I have absolutely no idea!!

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,263

    Re: Extracting lines starting with a certain number in a cell.

    Glad to have helped (in part).

+ 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] trying to set a cell to take a phone number starting with +
    By RodneyB in forum Excel General
    Replies: 6
    Last Post: 04-29-2021, 06:22 AM
  2. [SOLVED] Extracting a certain number of lines of text
    By L.LEE in forum Excel General
    Replies: 3
    Last Post: 02-06-2016, 09:49 AM
  3. Replies: 3
    Last Post: 11-21-2012, 03:28 PM
  4. Replies: 5
    Last Post: 09-27-2012, 07:30 PM
  5. [SOLVED] Print X number of copies starting with cell value
    By Nu2Java in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2012, 10:05 PM
  6. Replies: 3
    Last Post: 02-27-2010, 08:48 AM
  7. Extracting a specific number of lines from a file
    By paddyberk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2010, 12:08 PM

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