+ Reply to Thread
Results 1 to 15 of 15

Extract cells if they have 2 words (or one space)

  1. #1
    Registered User
    Join Date
    09-16-2017
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    6

    Extract cells if they have 2 words (or one space)

    Hi, Excel begginer here. I solved this like a month ago and now I can't remember how I did it... LUL

    I have a column with text and need a formula to find and extract the cells that have just two words (or one space). Like this:

    excel1.PNG

    Thank you in advanced.
    Attached Images Attached Images
    Last edited by ThunderRoad; 09-16-2017 at 01:22 PM. Reason: i'm stupid

  2. #2
    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
    44,001

    Re: Extract cells if they have 2 words (or one space)

    One way, using an array formula:

    =IFERROR(TRIM(INDEX(A:A,SMALL(IF(LEN(TRIM($A$1:$A$7))-LEN(TRIM(SUBSTITUTE($A$1:$A$7," ","")))=1,ROW($A$1:$A$7)),ROWS(C$1:C1)))),"")

    Array Formulae are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see curly brackets { } - or "curly braces" for those of you in the USA, or "flower brackets" for those of you in India - appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...
    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

  3. #3
    Registered User
    Join Date
    09-16-2017
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    6

    Re: Extract cells if they have 2 words (or one space)

    Hey Glenn, thanks for the answer. That's right, an array formula.

    I can't make it work with my original data.

    Please Login or Register  to view this content.
    are the columns right? So if I have 1000 columns it should be
    Please Login or Register  to view this content.
    .


    For reference this is my orginal file: https://drive.google.com/open?id=0Bw...015UVUxQkVkX2c
    And the solution I did back in July: https://drive.google.com/open?id=0Bw...TFENmlOdlJJUGs
    Last edited by ThunderRoad; 09-17-2017 at 06:05 AM.

  4. #4
    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
    44,001

    Re: Extract cells if they have 2 words (or one space)

    What's the full formula that you are using... and in which cell did you enter it? are you sure that the array was set correctly? Did you see the { ... } around the formula in the formula bar?

    I am roaming on a slow metered connection and did not / will not download a 66 Mb file!!

  5. #5
    Forum Contributor shivya's Avatar
    Join Date
    08-19-2017
    Location
    Delhi, India
    MS-Off Ver
    2013
    Posts
    240

    Re: Extract cells if they have 2 words (or one space)

    =if(len(m7)-len(substitute(m7:m7," ",""))+1=2,m7:m7," ")

  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
    44,001

    Re: Extract cells if they have 2 words (or one space)

    Quote Originally Posted by shivya View Post
    =if(len(m7)-len(substitute(m7:m7," ",""))+1=2,m7:m7," ")
    That doesn't remove blank cells (see Post 1) and doesn't work if there is inadvertantly an additional space (or several spaces) between words...

  7. #7
    Registered User
    Join Date
    09-16-2017
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    6

    Re: Extract cells if they have 2 words (or one space)

    I entered it in C1. The array formulas is set correctly. I used exactly the formula you posted but then changed the $A$1:$A$7.

  8. #8
    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
    44,001

    Re: Extract cells if they have 2 words (or one space)

    So... what are you seeing? Put the cursor in C1 (so I can see the formula in the formula bar) and post a screenshot (usually I hate screenshots...)

  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
    44,001

    Re: Extract cells if they have 2 words (or one space)

    You're in Spain. I didn't notice. Did you change the , into ; ?

    Normally, I'm in Ireland, but right now I'm in the middle of the Ebro delta...

  10. #10
    Registered User
    Join Date
    09-16-2017
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    6

    Re: Extract cells if they have 2 words (or one space)

    Thanks for your help Glenn.

    Yes, I changed the commas for semicolons. By the way, there is no need to check for multiple spaces, I made sure of that with regular expressions.

    The document is a .csv not Excel format though I don't think that matters, right? This is what I see:

    https://i.imgur.com/mOgbi23.gif

    The first occurence shows correctly when entering the array formula but when I drag nothing happens.

    This is a subset of my original file (13KB) in case it helps https://drive.google.com/open?id=0Bw...lQ3OHdvN28wa1k

    PS: Hope you are having a nice time in Cataluņa

  11. #11
    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
    44,001

    Re: Extract cells if they have 2 words (or one space)

    Array formulae don't work in CSV files (I'm 95% certain). The formula results convert to values, I think. Can't you save as .xlsx???

  12. #12
    Registered User
    Join Date
    09-16-2017
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    6

    Re: Extract cells if they have 2 words (or one space)

    The subset I upoaded of my original file in my previous message is a .xlsx and have the same issue.

  13. #13
    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
    44,001

    Re: Extract cells if they have 2 words (or one space)

    In your .xlsx, you had not changed the range from rows 1-7 to 1-120....

    =IFERROR(TRIM(INDEX(A:A,SMALL(IF(LEN(TRIM($A$1:$A$120))-LEN(TRIM(SUBSTITUTE($A$1:$A$120," ","")))=1,ROW($A$1:$A$120)),ROWS(C$1:C1)))),"")

    It works fine...

  14. #14
    Registered User
    Join Date
    09-16-2017
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    6

    Re: Extract cells if they have 2 words (or one space)

    Thanks Glenn. One question, why that range ($A$1:$A$120) needs to be bigger that the actual range of column A?

  15. #15
    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
    44,001

    Re: Extract cells if they have 2 words (or one space)

    No reason.... other than that you can make the range a bit longer, if additional values will be added.

    Anyhow...You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.

+ 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] extract space-separated words in a cell into an array
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-18-2017, 05:09 AM
  2. [SOLVED] Extract words till last, finding the 5th space from last
    By rajani.indegene in forum Excel General
    Replies: 3
    Last Post: 08-17-2015, 05:39 AM
  3. Extract words from cells and IF statement
    By pomper in forum Excel General
    Replies: 4
    Last Post: 03-14-2015, 02:23 PM
  4. [SOLVED] How can I extract first words from cells.
    By pomper in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2015, 01:02 AM
  5. [SOLVED] Extract words from cells into a new cell
    By soli004 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-16-2014, 08:41 AM
  6. Extract words from cells containing text
    By Pelona in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-02-2013, 05:17 PM
  7. Extract specific words from cells
    By Santa-D in forum Excel General
    Replies: 6
    Last Post: 06-18-2006, 11:10 PM

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