As the title already mentioned, I want to check if a certain text string contains any special characters.
Currently I have created a column with the characters which are allowed (ASCII range 32-122). And I would like a formula which returns 'ok', if the cell only contains characters which are allowed and 'not ok' if the cell contains any character that is not allowed.
However, Is this even possible without using a for loop? (thus without vba)
With your string to check in A1:
EDIT If the character strings to be checked might include Unicode characters, then you must use the UNICODE function in place of the CODE function. I believe this function became available in Excel 2013.
Assuming that your list of valid characters is in
A1:A91
and that the first entry for which you wish to perform the test is inB1
, enter this formula inC1
:=IF(LEN(B1)=0,"",REPT("not ",SUMPRODUCT(0+(ISNUMBER(MATCH(MID(B1,ROW(INDEX(B:B,1):INDEX(B:B,LEN(B1))),1),$A$1:$A$91,0))))<>LEN(B1))&"ok")
Copy down to give similar results for strings in
B2
,B3
, etc.We can in fact do without the use of an explicit list within the worksheet, viz:
=IF(LEN(B1)=0,"",REPT("not ",SUMPRODUCT(0+(ABS(77-CODE(MID(B1,ROW(INDEX(B:B,1):INDEX(B:B,LEN(B1))),1)))>45)))&"ok")
Regards
Use OR with FIND function and return with IF function