View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
keiji kounoike keiji kounoike is offline
external usenet poster
 
Posts: 199
Default Check that only ASCII chars are used

I think the code below should be

If IsNumeric(cel) Then
bIsASCII = True
Else
bIsASCII = IsAllASCII(ba)
End If


bIsASCII = IsAllASCII(ba)

IsNumeric returns true even if a number consist of None ASCII characters.

Keiji

Peter T wrote:
What you now say you want is very different to what you asked in your OP

this is only lightly tested -

Private Sub Worksheet_Change(ByVal Target As Range)
Dim bIsASCII As Boolean
Dim nClr1 As Long, nClr2 As Long
Dim ba() As Byte
Dim cel As Range

For Each cel In Target
ba = CStr(cel.Value)

If IsNumeric(cel) Then
bIsASCII = True
Else
bIsASCII = IsAllASCII(ba)
End If

With cel.Interior
nClr1 = .ColorIndex
nClr2 = 0
If bIsASCII Then
If nClr1 = 38 Then nClr2 = xlNone
Else
If nClr1 < 38 Then nClr2 = 38
End If
If nClr2 Then .ColorIndex = nClr2

End With
Next
End Sub

Function IsAllASCII(ba() As Byte) As Boolean
Dim bFlag As Boolean
Dim i As Long

For i = 0 To UBound(ba) - 1 Step 2
If ba(i) < 128 And ba(i + 1) = 0 Then
' it's an ASCII
Else
bFlag = True
Exit For
End If
Next
IsAllASCII = Not bFlag

End Function

Regards,
Peter T

"Makelei" wrote in message
...
Hi,
I just want to high light the cell with pink. I have about 30 000 rows and
30 columns in use.

This is to be used as data is entered to cell. Sub Worksheet_Change(ByVal
Target As Range)

BR
MakeLei

"Peter T" wrote:

So are you saying you want to check if any text cells contain characters
in
the range chr(x) where x is between 128 and 255

Also, could any formula cells return text with these characters.

For the result do you just want a yes/no answer or any information about
which cells contain non ASCII characte5rs

Regards,
Peter T



"Makelei" wrote in message
...
Hi,
xls and 2003

BR
MakeLei

"Peter T" wrote:

what sort of file, xls, txt....

Regards,
Peter T

"Makelei" wrote in message
...
Hi,
What would be the possibilities to check that only ASCII chars are
used
within one file?

Thanks in advance once again
Markku