To check whether a cell only contains a-z or 1-9 characters?

x-amount

Active Member
Joined
May 16, 2003
Messages
260
Is there a formula to show (true or false) whether a cell contains any characters that aren't a letter or number without resorting to vba?

Cheers,

x
 
Hi there!

This is brilliant! I appreciate it!

However, I tried to implement its concept with a slight variation and it did not work.

How can you scan only the first few characters in the cell rather than all the characters? I tried replacing Lens with LEFT and it did not work, as follows:

=(SUMPRODUCT(--(MOD(MATCH(CODE(MID('PL & BS Leadsheets'!$A5,ROW(INDEX('PL & BS Leadsheets'!A:A,1):INDEX('PL & BS Leadsheets'!A:A,LEFT('PL & BS Leadsheets'!A5,3))),1)),{0,48,58,65,91,97,123}),2)=0)))=LEFT('PL & BS Leadsheets'!A5,3)

I only want to check if the first letter in the cell IS an a-z or A-Z?? If so (i.e true), I will tie it into a Vlookup to return that cell.
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Sorry typo:

=(SUMPRODUCT(--(MOD(MATCH(CODE(MID('PL & BS Leadsheets'!$A5,ROW(INDEX('PL & BS Leadsheets'!A:A,1):INDEX('PL & BS Leadsheets'!A:A,LEFT('PL & BS Leadsheets'!A5,1))),1)),{0,48,58,65,91,97,123}),2)=0)))=LEFT('PL & BS Leadsheets'!A5,1)
 
Upvote 0
Hi,

If you Only want to check the First character of a cell for a-z or A-Z, this is much simpler:


Book1
ABC
3bobTRUE
4345FALSE
523bobFALSE
6jack678TRUE
Sheet493
Cell Formulas
RangeFormula
C3=AND(CODE(UPPER(A3))>64,CODE(UPPER(A3))<91)
 
Upvote 0
Hi!!

Thank you very much for that. Which part of that code only checks for the first character though? Does the CODE function by default only check the first character?
 
Upvote 0
Yes, that's right.

Just like if you use the LEFT function like LEFT(A1), without specifying the [num_chars], it defaults to 1, but with CODE, it Only checks the 1st character by default.
 
Upvote 0
Oh nice! Thanks for that.

I have an extension to what I am trying to do in case you are that proficient and do not mind giving it a crack.

So finding the first character with a letter works fine; I used it in this way:

=IF(AND(CODE(UPPER('PL & BS Leadsheets'!A5))>64,CODE(UPPER('PL & BS Leadsheets'!A5))<91),'PL & BS Leadsheets'!A5,0)

So pretty much to return the value in that cell. However, when I go on to check the next cell if it is false then it returns 0 and moves on. BUT that is a problem because I will end up having more 0's than actual items with the actual cells returned (i.e. those starting with a letter)

I believe I have to LOOP though and if it is true than returns that cell value, otherwise skips and checks next cell (i.e. 'PL & BS Leadsheets'!A6) and so on to 'PL & BS Leadsheets'!A7 etc. Rather than leaving me with a 0 and taking up rows unnecessarily. Is that possible? And vba might be the way right? Which is fine if you know how to do it.
 
Upvote 0
just a slight change to jtakw's formula : =ABS(CODE(UPPER(A3))-77.5)<13

that was to answer your question about the first letter

the newest question is a bit different - suggest you'd best start a new thread & also to explain what is being done.
when the fuller picture of the requirement is known there might be a totally different (& better) approach available.
And a new question will get more attention (newer readers) too
 
Upvote 0
To check if the first charater of a cell is a letter, I'd use

=AND(A1>="a",LEFT(A1)<="z")

easy to read
 
Upvote 0
I like that, pgc

However it also returns true for all these characters,
[TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"]ƒŠŒ™šœŸªºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top