Return True if cell contains special character

L

linglc

How do I test if a cell has any of the special characters e.g. *,?,/
Thanks for any help.
 
G

Greg Wilson

Try:

Function CellHasSpecChar(c As Range) As Boolean
CellHasSpecChar = c.Value Like "*[?/*]*"
End Function

Sub TestIt()
MsgBox CellHasSpecChar(ActiveCell)
End Sub

Regards,
Greg
 
B

Bob Phillips

For ? and / you can use

=ISNUMBER(FIND("/",A2)) etc..

For *, best to use

=ISNUMBER(FIND(CHAR(42),A2))

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
B

Bob Phillips

If you want the test all in one, try

=SUMPRODUCT(--(ISNUMBER(FIND({"*","/","?"},A1))))>0

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Top