How to Count Characters in Microsoft Excel Cells
Counting characters in an Excel cell is a lot easier than you might think. With a few simple formulas, you can count the number of characters in a single cell or multiple cells as well as get a total of specific characters.
If you’re preparing to export your data and must limit the characters per cell or want to find the number of occurrences of a particular character, here’s how in Microsoft Excel.
Count Characters in a Single Cell in Excel
To get the total number of characters in a cell, you’ll use the Excel LEN function. The syntax for the formula is simply LEN(cell), where you enter a cell reference for the argument.
As an example, you can count the characters in cell A2 using this formula:
=LEN(A2)
Remember that both punctuation marks and spaces count as characters, as do any spaces after the last character in the string.
Tip: You can also count the number of bytes in a cell using the LENB function. For instance, use =LENB(A2) for the above example.
Count Characters in Multiple Cells
Maybe you want the number of characters in multiple cells. You can use the LEN function and add the SUM function to the formula.
For example, with the following formula you can count the number of characters in cells A2, A4, and A6:
=SUM(LEN(A2),LEN(A4),LEN(A6))
Count Characters in a Cell Range
If you want to get the total number of characters in multiple adjacent cells, you can easily list out each cell reference using the formula above, but there’s a better way. You’ll still use the LEN and SUM functions to count characters in a range of cells.
For instance, you can obtain the number of characters in cells A2 through A4 with this formula:
=SUM(LEN(A2:A4))
As you can see, you just add the cell range within the LEN part of the formula to get your total.
Tip: If you’re familiar with the SUMPRODUCT function, you can use it the same way as the SUM function in this case. For our example, you could enter =SUMPRODUCT(LEN(A2:A4)) for the same result.
Multiple Cell Ranges
To count characters in two different cell ranges, you can continue to use the SUM and LEN functions.
Here, we’ll get the count for cells A2 through A4 plus C2 through C4 with this formula:
=SUM(LEN(A2:A4),LEN(C2:C4))
In this case, you simply add both LEN formulas within the parentheses for the SUM function’s formula.
Count Specific Characters in a Cell in Excel
Maybe it’s the count of a specific character you need to find. For this, you’ll use LEN with the SUBSTITUTE function.
In this example, we want to count the number of L’s in cell A1. You would use this formula:
=LEN(A2)-LEN(SUBSTITUTE(A2,”L”,””))
You can see our result of 1 is correct. Here’s a breakdown of the formula structure from the inside out:
- SUBSTITUTE(A2,”L”,””) replaces all instances of the letter L with an empty string in cell A2.
- LEN(SUBSTITUTE(A2,”L”,””)) counts the characters in cell A2 (without the letter L).
- LEN(A2) counts the total number of characters in cell A2.
- LEN(A2)-LEN(SUBSTITUTE(A2,”L”,””)) subtracts the character count (without the letter L) from the total number of characters in cell A2.
Specific Characters Ignoring Letter Case
As you’ll notice, the above formula only gives us one instance of the letter L as the result. This is because the formula contains the uppercase letter L, so it doesn’t look for lowercase letters.
To account for this case-sensitivity, you can add either UPPER or LOWER to the SUBSTITUTE formula. In a nutshell, this then replaces all occurrences, regardless of case, with the empty text string.
Using the same example, we’ll add UPPER to the formula as follows:
=LEN(A2)-LEN(SUBSTITUTE(UPPER(A2),”L”,””))
This time, we receive the result of 3 which includes both upper and lowercase L’s.
Count Specific Characters in a Cell Range
Want to take what you’ve learned so far and go even further? In this last section we’ll show you how to count a specific character in a range of cells. You’ll basically combine LEN, SUBSTITUTE, and SUM.
With this formula, you can count the number of L’s in the cell range A2 through A4:
=SUM(LEN(A2:A4)-LEN(SUBSTITUTE(UPPER(A2:A4),”L”,””)))
Here, we keep UPPER in the SUBSTITUTE formula to find all instances of the letter L regardless of letter case.
Once you start using these functions and formulas in your worksheet, counting characters in Excel becomes easier each time. No matter what you need the character count for, let Excel do the work instead of counting characters manually.
For more, check out our tutorial for using COUNTIFS, SUMIFS, and AVERAGEIFS in Microsoft Excel.
Source : How to Count Characters in Microsoft Excel Cells
Comments
Post a Comment