## Identify all characters in a cell value

Sometimes when you sort values you get unexpected results, the cause is probably unwanted characters in a cell.

The same thing may happen if you try to trim blanks in a cell value and it fails to remove the character that looks like the space character.

The TRIM function removes only ANSI character 32, however, the HTML blank character number 160 is not removed by TRIM.

The following array formula demonstrated in cell C3 in the picture above will convert each character in a cell value to it's corresponding ANSI number (PC).

This will make it easier for you see all the characters that cause problems. Cell B3 contains only letters and numbers, nothing weird.

Cell B5 contains a single space character, code 32. However, cell B4 contains an HTML character that looks like a space character. Cell B7 also has a weird space character, code 143.

As you can see the formula above assists you in finding weird characters.

### Explaining formula in cell C3

The INDEX function and the LEN function allows you to create a cell reference with as many rows as there are characters in cell C3.

$A$1:INDEX($A$1:$A$1000, LEN(B3))

becomes

$A$1:INDEX($A$1:$A$1000, 6) and returns $A$1:$A$6.

The ROW function then creates an array from 1 to the number of characters in cell C3.

ROW($A$1:INDEX($A$1:$A$1000, LEN(B3)))

becomes

ROW($A$1:$A$6) and returns {1;2;3;4;5;6}

Now it is time for the MID function to split each character in cell C3 to an array.

MID(B3, ROW($A$1:INDEX($A$1:$A$1000, LEN(B3))), 1)

becomes

MID("abc123", {1;2;3;4;5;6}, 1) and returns {"a";"b";"c";"1";"2";"3"}

The CODE function allows you to convert a character to ANSI code (PC). We are using an array so the function will convert all characters at the same time.

CODE(MID(B3, ROW($A$1:INDEX($A$1:$A$1000, LEN(B3))), 1)))

becomes

CODE({"a";"b";"c";"1";"2";"3"}) and returns {97;98;99;49;50;51}.

Lastly, the TEXTJOIN function concatenates all values in the array with the delimiting character , (comma).

TEXTJOIN(",", TRUE,CODE(MID(B3, ROW($A$1:INDEX($A$1:$A$1000, LEN(B3))), 1)))

becomes

TEXTJOIN(",", TRUE,{97;98;99;49;50;51}) and returns 97,98,99,49,50,51 in cell C3.

If the cell value is empty the formula returns #VALUE, the IFERROR function then displays "EMPTY".

### ANSI table

The picture above shows characters for number 1 to 255 (ANSI).

### Get Excel *.xlsx file

How to replace part of formula in all cells

This article explains how to substitute part of a formula across all cells in a worksheet. It is easier than […]

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form