First post, so I ll try to be as brief as possible.
I have a column of codes that should only have numbers or latin chars, but some of them may have been input incorrectly, that is some of them maybe cyrilic or other. For exp.: РE09000047 ор PE09000047.
I’ve got this code to work but it sees numbers as none latin
`
Sub NonLatin()
Dim cell As Object
For Each cell In Selection
s = cell.Value
For i = 1 To Len(s)
If Mid(s, i, 1) Like "[0x0000-0x007F]" Then
cell.Interior.ColorIndex = 6
cell.Characters(i, l).Font.Color = vbRed
cell.Characters(i, l).Font.Bold = True
End If
Next
Next
End Sub
It makes cell yellow, and none latin chars red and bolded. But also numbers. Any thoughts how I can make this work?
>Solution :
You can use a different approach to check for non-Latin characters.
Sub NonLatin()
Dim cell As Range
Dim s As String
Dim i As Integer
Dim char As String
For Each cell In Selection
s = cell.Value
For i = 1 To Len(s)
char = Mid(s, i, 1)
' Check if the character is not a number and not a Latin letter
If Not (char Like "[0-9]" Or char Like "[A-Za-z]") Then
cell.Interior.ColorIndex = 6 ' Yellow background for the cell
cell.Characters(i, 1).Font.Color = vbRed ' Red font for non-Latin characters
cell.Characters(i, 1).Font.Bold = True ' Bold font for non-Latin characters
End If
Next i
Next cell
End Sub
Try this, that should work i think.