I need a non-VBA formula or array formula that provides me with the location of the first non-alphanumeric character in a string. So, Ascii code is NOT 65-90, 97-122, nor 48-57 inclusive.
I need a non-VBA formula or array formula that provides me with the location of the first non-alphanumeric character in a string. So, Ascii code is NOT 65-90, 97-122, nor 48-57 inclusive.
For a string in cell A2, Array-Enter - enter using Ctrl-Shift-Enter:
=MIN(IF(ISERROR(SEARCH(MID(A2,ROW(INDIRECT("A1:A"&LEN(A2))),1),"0123456789qwertyuiopasdfghjklzxcvbnm")),ROW(INDIRECT("A1:A"&LEN(A2)))))
Or if you like things in order
=MIN(IF(ISERROR(SEARCH(MID(A2,ROW(INDIRECT("A1:A"&LEN(A2))),1),"0123456789abcdefghijklmnopqrstuvwxyz")),ROW(INDIRECT("A1:A"&LEN(A2)))))
Bernie Deitrick
Excel MVP 2000-2010
Hi Bernie, really appreciate quick response.
Array formula seems to work in nearly all cases. However, it doesn't appear to recognize an asterisk as a non-alphanumeric value.
"HARRIS*Johnson #0 1452 Albany #5122" ---> formula calculates 15.
* and ? will give you problems - so use this array-entered:
=MIN(IFERROR(SEARCH("~?",A2),LEN(A2)+1),IFERROR(SEARCH("~*",A2),LEN(A2)+1),IFERROR(1/(1/MIN(IF(ISERROR(SEARCH(MID(A2,ROW(INDIRECT("A1:A"&LEN(A2))),1),"0123456789abcdefghijklmnopqrstuvwxyz")),ROW(INDIRECT("A1:A"&LEN(A2)))))),LEN(A2)+1))
Sorry - your attachments come up as invalid.
Last edited by Bernie Deitrick; 04-12-2021 at 03:16 PM.
Hi Bernie, Sorry for crossed notes. Revised formula works great!
You are a formula wizard!
If you know a maximum length that you text will never be longer than (I have assumed 100 but you can change the two 100s if 100 is too small), then this much shorter array-entered** formula will also work...
Formula:Please Login or Register to view this content.
**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself
NOTE: My formula and Bernie's return different results when the text does not contain a non-alphanumeric character and when the text is blank (my formula returns 0 for both).
Last edited by Rick Rothstein; 04-12-2021 at 05:51 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks