[英]Excel invisible question mark
I have an extracted information from a system into an Excel file. 我将从系统中提取的信息提取到Excel文件中。 The names "Leone" seem the same but Excel recognize it differently.
“Leone”这两个名字看起来是一样的,但Excel对此有不同的认识。
Leone 塞拉利昂
Leone 塞拉利昂
The length of the string is not the same, and if I check the value with VBA an invisible ? 字符串的长度是不一样的,如果我用VBA检查值是不可见的? is the first character.
是第一个角色。
Could you help me how to get rid of the invisible characters? 你能帮助我摆脱看不见的角色吗?
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
. 而不是
If AscW(strChr) = 8203 Then
你也可以使用If AscW(strChr) > 255 Then
。
EDIT 1 : As per the suggestion of @YowE3K. 编辑1:根据@ YowE3K的建议。 Assuming you only have
Unicode 8203
in cells to be replaced. 假设您在要替换的单元格中只有
Unicode 8203
。
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
In general this is strange - this is how chrome renders the HTML from the question: 一般来说这很奇怪 - 这就是chrome从问题中呈现HTML的方式:
This is a workaround, that checks the characters of the string and builds a new one if one of them is equal to 63. Pretty much like a simple replace function: 这是一种解决方法,它检查字符串的字符并构建一个新的字符串,如果其中一个等于63.非常像一个简单的替换函数:
Public Function removeInvisible(rngRange As Range) As String
Dim cnt As Long
For cnt = 1 To Len(rngRange)
If AscW(Mid(rngRange, cnt, 1)) <> 8203 Then
removeInvisible = removeInvisible & Mid(rngRange, cnt, 1)
End If
Next cnt
End Function
If the text has come from a copy/paste it might have taken in some other non printable characters. 如果文本来自复制/粘贴,则可能包含其他一些不可打印的字符。 These might be displayed in the VBA editor as ?
这些可能会在VBA编辑器中显示为? which is often the way that unicode characters are rendered when the font does not support them.
这通常是字体不支持时呈现unicode字符的方式。
I would try the formula =CODE(LEFT(A3,1))
in one of the cells to see what the Unicode code point of the invisible character was. 我会在其中一个单元格中尝试使用公式
=CODE(LEFT(A3,1))
来查看隐形字符的Unicode代码点是什么。
If it turns out to be a non ascii chat then you could write a macro to strip out the characters that are problematic based on their code values. 如果结果是非ascii聊天,那么你可以编写一个宏来根据代码值去掉有问题的字符。
To remove multiple occurrences of non-ascii characters from all cells of your range you can use this. 要从您的范围的所有单元格中删除多次出现的非ascii字符,您可以使用此字符。
Option Explicit
Sub test()
Dim regEx As Object
Dim temparray() As String
Dim myrange As Range
Dim lrow As Long
Dim lcol As Long
Dim counter As Long
Dim i As Long
Dim j As Long
Set regEx = CreateObject("vbscript.regexp")
With regEx
.Pattern = "[^\u0000-\u007F]"
.MultiLine = False
.Global = True
.IgnoreCase = False
End With
'set your last row and column
lrow = 5
lcol = 5
ReDim temparray(1 To lrow, 1 To lcol)
Set myrange = Sheets("Sheet1").Range(Cells(1, 1), Cells(lrow, lcol))
Application.ScreenUpdating = False
counter = 0
For i = 1 To lrow
For j = 1 To lcol
temparray(i, j) = regEx.Replace(myrange.Cells(i, j).Value, "")
counter = counter + 1
Next j
Next i
myrange.Value = temparray
Application.ScreenUpdating = True
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.