+ Reply to Thread
Results 1 to 8 of 8

Formula to count the number of spaces before text/number is written in a cell.

  1. #1
    Registered User
    Join Date
    06-10-2013
    Location
    london, engalnd
    MS-Off Ver
    Excel 2010
    Posts
    10

    Formula to count the number of spaces before text/number is written in a cell.

    Hi ALL,

    I have data in a cell. For example in cell B2 I have the word Apple.
    but before the word Apple is a space
    In cell A2 I want the number 1. which is the number of spaces before apple.

    Another example. In cell B3 I have the word A1234.
    but before the word A1234 I have 10 spaces.
    In cell B3 I would like the number 10.

    I have attached an example.

    thanks

    Formula for number of spaces.xlsx

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,599

    Re: Formula to count the number of spaces before text/number is written in a cell.

    =len(b2)-len(trim(b2))
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    06-10-2013
    Location
    london, engalnd
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Formula to count the number of spaces before text/number is written in a cell.

    Hi ProtonLeah,

    Thanks, that works a treat. however, if the cell is blank it return the number 0. what do I need to change in the formula so that when its a blank cell it returns nothing (i.e. no number 0)

    Thanks

  4. #4
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Formula to count the number of spaces before text/number is written in a cell.

    another option solution
    =SUMPRODUCT((MID(B2,ROW($1:$100),1)=" ")*1)

  5. #5
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Formula to count the number of spaces before text/number is written in a cell.

    Quote Originally Posted by kmis View Post
    Thanks, that works a treat. however, if the cell is blank it return the number 0. what do I need to change in the formula so that when its a blank cell it returns nothing (i.e. no number 0)
    Format cells as 0;;""
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  6. #6
    Registered User
    Join Date
    06-10-2013
    Location
    london, engalnd
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Formula to count the number of spaces before text/number is written in a cell.

    Thanks Ghozi.

  7. #7
    Registered User
    Join Date
    06-10-2013
    Location
    london, engalnd
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Formula to count the number of spaces before text/number is written in a cell.

    Quote Originally Posted by Ace_XL View Post
    Format cells as 0;;""

    not sure what you mean by this ACE_XL??

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,599

    Re: Formula to count the number of spaces before text/number is written in a cell.

    =if(b2<>"",len(b2)-len(trim(b2)),"")

+ 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