ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Problem with counting characters in a cell (https://www.excelbanter.com/excel-worksheet-functions/32616-problem-counting-characters-cell.html)

Tink

Problem with counting characters in a cell
 
Hi,

I'm trying to count the number of characters in a cell. At the moment i've
tried using =LEN(A2). This works fine when all characters are numeric, but
when there are letters in the mix, it shows the total number as 30 regardless
of whether there are 8, 12 or 14 characters in the code.

Someone please help!!!

bj

There may really be 30 characters
If this is data which has come in from an outside sourse there may be spaces
try
=len(trim(A2))
You may have to modify how the cells are referenced or handeled if this is a
significant issue.



"Tink" wrote:

Hi,

I'm trying to count the number of characters in a cell. At the moment i've
tried using =LEN(A2). This works fine when all characters are numeric, but
when there are letters in the mix, it shows the total number as 30 regardless
of whether there are 8, 12 or 14 characters in the code.

Someone please help!!!


Dave Peterson

It should work ok with alph/numeric values.

I'd bet you have some extra spaces (or non-breaking spaces) in those cells.

=len(trim(substitute(a1,char(160)," ")))

might show you the problem.

If it turns out that you have spaces (or those non-breaking spaces), David
McRitchie has some code that will help clean this junk up:

http://www.mvps.org/dmcritchie/excel/join.htm#trimall
(look for "Sub Trimall()")

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Tink wrote:

Hi,

I'm trying to count the number of characters in a cell. At the moment i've
tried using =LEN(A2). This works fine when all characters are numeric, but
when there are letters in the mix, it shows the total number as 30 regardless
of whether there are 8, 12 or 14 characters in the code.

Someone please help!!!


--

Dave Peterson


All times are GMT +1. The time now is 06:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com