简体   繁体   中英

Excel VBA - Check if cell contains specific characters

I'm using the following to check if a cell contains any invalid characters.

If Target Like "*[\!%^:~#|@.;`\/*$,]*" Then

This works fine and return the correct error message.

I'd like to add Double Quotes " to the check, but when I add " I get errors.

How do I do this?

Thanks

Doubling the quotes should do it:

Like "*[\!%^:~#|@.;`\/*$,""]*"  

Note that \ is the LIKE escape char, so "\." means in fact "!".

Test:

a = "abc""de"
? a
abc"de
? a like "*[b]*"
True
? a like "*[""]*"
True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM