I recently inherited a VBA macro that needs to have validation logic added to it. I need to be able to determine if any characters in a text based cell are non ASCII characters (i.e. have a binary value > 0x7F). The cells may contain some carriage control values (particularly linefeeds) that need to be retained (so the CLEAN function does not work for this validation). I have tried the IsText function, but found that it will interpret UTF-8 character sequences as valid text (which I don’t want).
I don’t need to actually manipulate the string, I just want to display an error to the user that runs the macro to tell him that there are invalid (non-ASCII) characters in a specific cell.
The asc(character) command will convert a character to it’s ASCII value.
hex(asc(character)) will convert the character to it’s HEX value.
Once you’ve done that you can easily do some comparisons to determine if the data is bad and toss the errors if required.
Here’s some sample code: http://www.freevbcode.com/ShowCode.asp?ID=4486