Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel invisible question mark

Tags:

excel

vba

I have an extracted information from a system into an Excel file. The names "Leone" seem the same but Excel recognize it differently.

Leone

​Leone

The length of the string is not the same, and if I check the value with VBA an invisible ? is the first character.

Could you help me how to get rid of the invisible characters?

enter image description here

like image 886
Erika Avatar asked Apr 07 '26 12:04

Erika


1 Answers

To get rid of all invisible ? you may try this.

Sub CleanUnicode()
    Dim n As Long, strClean As String, strChr As String
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Sheets("Sheet3")  'change Sheet3 to data sheet
    For Each cel In ws.Range("A1:A10")      'change A1:A10 to working range
        strClean = cel.Value
        For n = Len(strClean) To 1 Step -1
            strChr = Mid(strClean, n, 1)
            If AscW(strChr) = 8203 Then     '? is unicode character 8203
                strClean = Replace(strClean, strChr, "")
            End If
        Next
        cel.Value = WorksheetFunction.Trim(strClean)
    Next cel
End Sub

Instead of If AscW(strChr) = 8203 Then you can also use If AscW(strChr) > 255 Then.

EDIT 1 : As per the suggestion of @YowE3K. Assuming you only have Unicode 8203 in cells to be replaced.

Sub CleanUnicode()
    Dim n As Long, strClean As String, strChr As String
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Sheets("Sheet3")  'change Sheet3 to data sheet
    For Each cel In ws.Range("A1:A10")      'change A1:A10 to working range
        cel.Value = Replace(cel.Value, ChrW(8203), "")
    Next cel
End Sub

Got this from here.

like image 147
Mrig Avatar answered Apr 10 '26 01:04

Mrig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!