Re: test for "special characters" in text

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Frank Cutre wrote...
>I need to make sure that a cell contains NO SPECIAL CHARACTERS (including
>the <SpaceBar>) during data entry.
>
>I've tried:
>=len(cellReference)=len(substitute(cellReference,or(char(32),char(34),...etc
....
>but Excel doesn't like the OR funtion (2nd parameter) inside SUBSTITUTE.
....

Looks like you want only letters and digits. There's no way to prevent
users from typing them, and if they're clever enough to know how to use
copy & paste, there's no way to use data validation to prevent them
from being entered. That leaves removing them yourself or forcing your
users to remove them.

Doing it yourself, there's no 1-cell way to do it without resorting to
VBA. You could use a udf like the following.


Function foo(s As String, p As String) As String
Dim c As String * 1, k As Long, n As Long

n = Len(s)

For k = 1 To n
c = Mid$(s, k, 1)
If c Like p Then foo = foo & c
Next k

End Function


and use it in formulas like

=foo(B5,"[A-Za-z0-9]")

The other alternative, make your users clean their own entries, can be
done by ensuring that invalid entries trigger nothing but errors in
formula results along with messages that tell the user that it's their
own invalid entries that caused the errors. That can be done with
built-in functions and one defined name, e.g., define the name N
referring to 128 or so, seq referring to

=ROW(INDEX($1:$65536,1,1):INDEX($1:$65536,N,1))

then try the *array* formula

=0/(COUNT(FIND(MID(UPPER(B5),seq,1),
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))=N)

which should return 0 when cell B5 contains nothing but letters and
decimal numerals but #DIV/0! when it contains any other characters.

In my experience nothing is more effective in motivating users to enter
valid data than giving them nothing but errors and diagnostic messages
explaining that those errors are due to invalid entries. If a user can
only print off pages full of errors and text stating that the errors
are their own fault, they can't complain to their bosses or to IT
support. All they can do is fix their own errors. This won't win you
popularity contests among your users, but it will ensure they do what
they're supposed to do.

.



Relevant Pages

  • VB, implementing the high score within this code
    ... Private possibleAs String ... Private Function SolvePuzzleAs Boolean ... ' Calculates the possible values for all the cell ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Formulas containing hard coded values
    ... Dim R As Range, sdoit As String ... MsgBox "Cell contains hard codes" ... Dim Fml As String, LCtext As String ... For Each Rng In R.Precedents.Areas ...
    (microsoft.public.excel.programming)
  • Re: Marking points read for coordinates
    ... In "Private Sub GetCoordinates()" comment all the code between ... (ByVal lpClassName As String, ByVal lpWindowName As String) ... ' cell A1 which is the base for all object coordinates on a sheet. ... Dim chtObj As ChartObject ...
    (microsoft.public.excel.programming)
  • Re: Text formatted cells displaying numbers in scientific format
    ... When it 'sees' a large number it uses scientific format since ... I accept that Excel can't handle numbers greater than 15 digits and your ... string was 16 digits or more to be converted to a scientific value. ... It just doesn't display correctly in the cell (except after entering ...
    (microsoft.public.excel)
  • Re: Parsing and Counting Matches - My State Table.xls (0/1)
    ... ' Search for occurance in a Cell of a string found in a specific Cell ... ' Need nested loops to traverse both the Search Cell and the String Cells. ... Dim CellString As String 'Cell to search ... CellRow = 2 ' Initialize Cell Row ...
    (microsoft.public.excel)