+ Reply to Thread
Results 1 to 8 of 8

Excel 2007 : How to filter cells that contain specific number of words?

  1. #1
    Registered User
    Join Date
    04-15-2011
    Location
    Sofia
    MS-Off Ver
    Excel 2007
    Posts
    67

    How to filter cells that contain specific number of words?

    Hello,

    I have a column in which every cell contains a different number of words. Is it possible to filter only these cells that contain one or two words?

    Thanks!
    Last edited by emil9216; 01-24-2012 at 06:25 PM.

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: How to filter cells that contain specific number of words?

    Hi Emil

    One way is this.

    Let's say that your words are in column A, starting in A1.

    So in B1, use this formula.

    =LEN(TRIM(A1))-LEN(SUBSTITUTE(A1;" ";""))+1

    This will show you, how many words are in A1. Copy down.

    Then use Auto filter by column B, to get your result.

    Hope to helps you.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

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

    Re: How to filter cells that contain specific number of words?

    Hi emil9216,

    How about a User Defined Function (UDF) to count words in a cell. This is really the number of spaces plus 1.
    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    04-15-2011
    Location
    Sofia
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: How to filter cells that contain specific number of words?

    @Fotis1991

    I tried the formula but it doesn't seem to work. If i paste the formula in B1 nothing happening.

    @MarvinP

    Thanks, but i am not sure how to use the User Defined Function. Is it something like creating macro: from the Visual Basic button, Insert>Module and paste the code in the window. Because i tried this but it doesn't work.

  5. #5
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: How to filter cells that contain specific number of words?

    Hi Emil

    Pls take a look to the sample.

    Hope to be OK, now.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-15-2011
    Location
    Sofia
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: How to filter cells that contain specific number of words?

    Thanks, now it is working but i think the formula in your post didn't work because it has semicolons instead of commas in it.

  7. #7
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: How to filter cells that contain specific number of words?

    You are welcome

    In my Excel addition, i have to use semicolons instead of commas, if i want my formulas to be ok!

    So, if you found your solution, mark your Thread, as SOLVED.

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

    Re: How to filter cells that contain specific number of words?

    Here is my UDF workbook attached for your examination.


    Also for those who like the TRIM function, it looks like the VBA Trim() doesn't do the same thing as:
    Application.WorksheetFunction.Trim().

    It looks like the VBA Trim() does NOT collapse double spaces to single spaces when not at the front or rear of the string. Who would have known, without a test?? This makes my above code different than the code inside the attached.
    Attached Files Attached Files

+ 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