Check if Cell contains alpha or numeric characters
Generic formula
=SUMPRODUCT(SEARCH(MID(Cell,ROW(INDIRECT("1:"&LEN(Cell))),1),"abcdefghijklmnopqrstuvwxyz"))
Explanation
To check the cell contains only alphabet or numeric characters, we can build up the formula as above.
In the example shown, the formula in C3 is:
=SUMPRODUCT(SEARCH(MID(B3,ROW(INDIRECT("1:"&LEN(B3))),1),"abcdefghijklmnopqrstuvwxyz"))
Note that this formula is doing and "absolute match" against the value "abcdefghijklmnopqrstuvwxyz". So you want to include space character include it in the value.
How this formula works
The core of this formula is SUMPRODUCT, which is simply retrieving a value from the array and provide the sum of the values.
=SUMPRODUCT(array)
To get the array value, we use SEARCH, configured for match the characters in the cell, against the given alphabet value, and return the array of number of the position of the alphabet in the value.
=SEARCH(MID(B3,ROW(INDIRECT("1:"&LEN(B3))),1),"abcdefghijklmnopqrstuvwxyz") // search the character against the value
LEN function get the number of character in the cell.=LEN(B3)
INDIRCT function returns number of times ROW function to be checked.
=ROW(INDIRECT("1:"&2)
MID function will now turn into array function and check each character of the word in
the cell against the value and return the number of the position of the character.
This formula returns #VALUE! error if B3 contains any non-letter characters and Number if B3 contains only letters or #REF! error if B3 is blank.=MID(B3,{$1:$2},1)
You can enclose this formula in an ISNUMBER or ISERR to convert this to a TRUE/FALSE value.
Replace the SEARCH with a FIND to make it case sensitive.
You can put any character in the "abc...xyz" string. This makes it easy to test of alphanumeric, or common punctuation, space etc.
The "1:"&LEN(A1) means that starting from the first letter, all the way to the last letter will be checked.
Changing that to "2:"&(LEN(A1)-1) will not check the first and last letters.
No comments:
Post a Comment