Concrete Repeating Characters in a Cell Formula
Well it seems like yesterday but it has been over a month since my last entry. I promised my children do not go to a worksheet during the holidays y. .. Almost completed!
I have sent many questions (I guess I should thank you ...) I'll try to answer as soon as possible. One of the most repeated was as follows:
I need to know the number of spaces containing a group of cells " .
We will use a fairly simple formula, I know I read somewhere long ago but I forgot where, with the functions LONG and REPLACE . We start from the following example :
We how many spaces each cell contains (a question that although it does not seem it can be very useful, for example, make formulas to separate cells in different names and surnames). What we do in essence is:
1. Count the total number of characters that contains the cell B3
2. Remove all whitespace from the text of B3 and C3 enter the result.
3. Count the total number of characters in C3.
4. Find the difference between the two totals. This difference will obviously be the number of blanks that have the cell B3.
Let's start with the goal of better understanding, at step 2. We will use the SUBSTITUTE function. This function replaces within a text string with a new one specific original. The syntax of this function is:
REPLACE (text ; old_text ; new_text ; núm_de_ocurrencia)
Text: is the text or a reference to a cell that contains text you want to replace characters.
old_text : the text to replace.
new_text: is the text you want to replace old_text.
Núm_de_ocurrencia: old_text specific instance you want to replace new_text. If the argument specifies núm_de_ocurrencia only will replace that instance of old_text. Otherwise, all instances of old_text text will be replaced with new_text.
So, we move into the cell C3 and type the following formula:
= SUBSTITUTE (B3, "";"") Note that the second argument is " space" and the third is "without any spaces. We are asking you to excel to replace white space that is for nothing. The result of this formula is this:
As you can see the contents of cell C3 is the same as that of the cell B3, but no spaces.
Once this is done the rest is easy. We can only "measure" the length of both cells and find the difference. To do this do the following:
in D3 type: = LEN (B3)
E3 wrote: = LEN (C3)
in F3 type: = B3-C3
Problem solved! Obviously if you only need the number of blanks can summarize all these formulas in the following (I write in cell C3):
= LEN (B3)-LEN (SUBSTITUTE (B3; " ";""))
In this case we have counted the number of blanks but you can use this formula to other characters by simply replacing the expression " by" a " , for example.