+ Reply to Thread
Results 1 to 11 of 11

Counting No of Characters Excluding Spaces

  1. #1
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Counting No of Characters Excluding Spaces

    I wish to count the number of characters in a particular cell, excluding any spaces, and display the number of characters in another cell. Spaces may be at the start, within the characters or at the end.

    I'm sure this is quite easy, but I just can't seem to make to work.

    Can someone please help?

    Thanks.

  2. #2
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,197

    Re: Counting No of Characters Excluding Spaces

    Try this

    =LEN(SUBSTITUTE(A1," ",""))

  3. #3
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Counting No of Characters Excluding Spaces

    Quote Originally Posted by Phuocam View Post
    Try this

    =LEN(SUBSTITUTE(A1," ",""))
    Perfect. Thanks heaps.

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,478

    Re: Counting No of Characters Excluding Spaces

    While I would use what Phuocam posted, I thought I would have some fun with this question (if you have xl365 that is)...

    =SUM(LEN(TEXTSPLIT(A1," ")))
    Last edited by Rick Rothstein; 11-14-2023 at 09:51 PM.

  5. #5
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Counting No of Characters Excluding Spaces

    Quote Originally Posted by Rick Rothstein View Post
    While I would use what Phuocam posted, I thought I would have some fun with this question (if you have xl365 that is)...

    =SUM(LEN(TEXTSPLIT(A1," ")))
    Works just as well. Any advantage of one over the other?

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,478

    Re: Counting No of Characters Excluding Spaces

    Quote Originally Posted by EdWoods View Post
    Works just as well. Any advantage of one over the other?
    Phuocam's formula is simpler (two function calls versus the three in mine) and I am thinking SUBSTITUTE may be less "demanding" than TEXTSPLIT. So for your question, I think Phuocam''s formula is better (which is why I said I would use it). However, if you changed your question to number of characters excluding spaces, commas and periods, then my formula could be easily modified to handle it...

    =SUM(LEN(TEXTSPLIT(A1,{" ",",","."})))

  7. #7
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Counting No of Characters Excluding Spaces

    Quote Originally Posted by Rick Rothstein View Post
    Phuocam's formula is simpler (two function calls versus the three in mine) and I am thinking SUBSTITUTE may be less "demanding" than TEXTSPLIT. So for your question, I think Phuocam''s formula is better (which is why I said I would use it). However, if you changed your question to number of characters excluding spaces, commas and periods, then my formula could be easily modified to handle it...

    =SUM(LEN(TEXTSPLIT(A1,{" ",",","."})))
    Thanks. Very handy to put in my "Solutions" spreadsheet.

  8. #8
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,478

    Re: Counting No of Characters Excluding Spaces

    Quote Originally Posted by EdWoods View Post
    Thanks. Very handy to put in my "Solutions" spreadsheet.
    You are quite welcome. Question - your profile says you are using xl2019, but it is my understanding that TEXTSPLIT is not in that version of Excel... am I wrong?

  9. #9
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Counting No of Characters Excluding Spaces

    Quote Originally Posted by Rick Rothstein View Post
    You are quite welcome. Question - your profile says you are using xl2019, but it is my understanding that TEXTSPLIT is not in that version of Excel... am I wrong?
    My profile is wrong. I'm on my work computer, which is 365.

    Just on my previous question, suppose I ONLY wanted to allow input of digits 0 - 9 ignoring any other key pressed. How would I go about that?

  10. #10
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.97.2 for Mac MS 365
    Posts
    8,708

    Re: Counting No of Characters Excluding Spaces

    When you note
    I ONLY wanted to allow input of digits 0 - 9
    you are not referring to your previous subject in this post about only counting characters in a cell - and now asking how to count only numbers in a cell ignoring blanks and text but putting a rule in place that does not allow text to be input into a cell, only numbers?

    But if you want to count the number of numbers in a cell that includes text this formula would work... =COUNT(--MID(A2,SEQUENCE(LEN(A2)),1))
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  11. #11
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Counting No of Characters Excluding Spaces

    Quote Originally Posted by Sam Capricci View Post
    When you note


    you are not referring to your previous subject in this post about only counting characters in a cell - and now asking how to count only numbers in a cell ignoring blanks and text but putting a rule in place that does not allow text to be input into a cell, only numbers?

    But if you want to count the number of numbers in a cell that includes text this formula would work... =COUNT(--MID(A2,SEQUENCE(LEN(A2)),1))
    Thanks Sam.

    Was interested in both scenarios.

    This isn't for my initial enquiry, but more of a "fact finder" for me to learn. Appreciate it.
    Last edited by EdWoods; 11-14-2023 at 11:52 PM.

+ 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] Counting Characters In Textbox Including Spaces?
    By jayfin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-27-2021, 02:19 PM
  2. remove all except a-z, korean characters and spaces
    By JossMedina in forum Excel General
    Replies: 2
    Last Post: 05-13-2020, 04:42 AM
  3. [SOLVED] vba to add spaces to end of cell text up to 30 characters only
    By phpolicylady in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-07-2015, 02:30 PM
  4. Sum total excluding rows with certain characters
    By Fien118 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-20-2014, 08:02 AM
  5. [SOLVED] Keep first 11 characters (including spaces) in a column.
    By janlee43 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-06-2013, 05:17 PM
  6. [SOLVED] Counting Alphabetic Letters alone inside the Cell excluding spaces
    By thilag in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-05-2013, 01:59 PM
  7. Excluding suffix characters
    By Tommy in forum Excel General
    Replies: 4
    Last Post: 01-13-2010, 01:32 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