+ Reply to Thread
Results 1 to 11 of 11

How do I filter cells that end with a space?

  1. #1
    Registered User
    Join Date
    06-08-2012
    Location
    Singapore, Singapore
    MS-Off Ver
    Excel 2010
    Posts
    11

    How do I filter cells that end with a space?

    Hi,

    Is this possible? I have thousands of names in one column and I'm trying to count them using =countif. Problem is, there's something wrong with the data and some of the names end in a space. My count becomes inaccurate since they count the ones with spaces separately.

    EX:
    mpsnoop
    mpsnoop(space)

    By right, the count should be 2 but since one has a space, it counts 1 and 1. I can't use text to columns either because some of the names are full names with spaces in between (ie mpsnoop snoop)

    Any help is greatly appreciated. Thanks!

    Regards,
    mpsnoop6

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: How do I filter cells that end with a space?

    Try SUMPRODUCT:
    =SUMPRODUCT((TRIM($A$1:$A$100)=$B$1)*1)
    With your given name in B1 and your name data in A1:A100
    Quang PT

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How do I filter cells that end with a space?

    like this, there's probably a better way however:
    PHP Code: 
    =SUM(IF(SUBSTITUTE(A1:A10," ","")="mpsnoop",1)) 
    or
    PHP Code: 
    =SUM(IF(TRIM(A1:A10," ","")="mpsnoop",1)) 
    This is an array formula so entered with Ctrl+Shift+Enter
    Last edited by Kyle123; 07-13-2012 at 07:45 AM.

  4. #4
    Registered User
    Join Date
    07-13-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: How do I filter cells that end with a space?

    To get rid of spaces before and after use =trim(A1). Then use this new column for what you want to do.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How do I filter cells that end with a space?

    That's what the above functions do they're both array formulas which means that you don't have to have a separate helper column with trimmed values

  6. #6
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How do I filter cells that end with a space?

    A simple, non-array option would be:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    where B1 holds the name to be counted

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,819

    Re: How do I filter cells that end with a space?

    You can use wildcards with COUNTIF, so try it like this:

    =COUNTIF(A:A,B1&"*")

    where B1 contains your name without the space.

    Hope this helps.

    Pete

  8. #8
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How do I filter cells that end with a space?

    I was going to suggest the wildacrd approach but it may lead to problems, like:

    Bill Smith as the name to be counted

    so using: =COUNTIF(A:A,"Bill Smith*")

    Bill Smithers would also be counted

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How do I filter cells that end with a space?

    assuming it IS a space and not char(10),char(0160) or such
    select column
    data /text to columns
    fixed width
    remove all the break marks
    click finish
    bye bye leading and trailing spaces
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  10. #10
    Registered User
    Join Date
    06-08-2012
    Location
    Singapore, Singapore
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How do I filter cells that end with a space?

    Hi all,

    Wow thanks for all the replies. Got everything I need now. Thanks again!

    Regards,
    mpsnoop6

  11. #11
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: How do I filter cells that end with a space?

    You're welcome. Please remember to mark your thread as SOLVED.

    Here's how:

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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