Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Highlight characters in cell that are not latin or numbers

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

`

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading