简体   繁体   English

Excel中的隐藏空间

[英]hidden space in excel

I tried almost all the methods (CLEAN,TRIM,SUBSTITUTE) trying to remove the character hiding in the beginning and the end of a text. 我尝试了几乎所有方法(CLEAN,TRIM,SUBSTITUTE),尝试删除隐藏在文本开头和结尾的字符。 In my case, I downloaded the bill of material report from oracle ERP and found that the item codes are a victim of hidden characters. 就我而言,我从oracle ERP中下载了物料清单报告,发现项目代码是隐藏字符的受害者。

After so many findings, I was able to trace which character is hidden and found out that it's a question mark'?' 经过如此多的发现,我能够找到隐藏了哪个字符,并发现这是一个问号'? (via VBA code in another thread) both at the front and the end. (通过另一个线程中的VBA代码)在前端和后端。 You can take this item code‭: ‭11301-21‬ 您可以输入此商品编号‭:‭11301-21‬

If you paste the above into your excel and see its length =LEN(), you can understand my problem much better. 如果将以上内容粘贴到excel中并查看其长度= LEN(),则可以更好地理解我的问题。

I need a good solution for this problem. 对于这个问题,我需要一个好的解决方案。 Therefore please help! 因此请帮忙!

Thank you very much in advance. 提前非常感谢您。

Thanks to Gary's Student , because his answer inspired me. 感谢Gary的Student ,因为他的回答启发了我。

Also, I used this answer for this code. 另外,我将此答案用于此代码。

This function will clean every single char of your data, so it should work for you. 此函数将清除您数据的每个字符,因此它应该对您有用。 You need 2 functions: 1 to clean the Unicode chars, and other one to clean your item codes_ 您需要2个功能:1个用于清除Unicode字符,另一种用于清除商品代码_

        Public Function CLEAN_ITEM_CODE(ByRef ThisCell As Range) As String
    If ThisCell.Count > 1 Or ThisCell.Count < 1 Then
        CLEAN_ITEM_CODE = "Only single cells allowed"
        Exit Function
    End If


    Dim ZZ As Byte

    For ZZ = 1 To Len(ThisCell.Value) Step 1
        CLEAN_ITEM_CODE = CLEAN_ITEM_CODE & GetStrippedText(Mid(ThisCell.Value, ZZ, 1))
    Next ZZ


    End Function

    Private Function GetStrippedText(txt As String) As String
If txt = "–" Then
    GetStrippedText = "–"
Else
    Dim regEx As Object

    Set regEx = CreateObject("vbscript.regexp")
    regEx.Pattern = "[^\u0000-\u007F]"
    GetStrippedText = regEx.Replace(txt, "")
End If

End Function

And this is what i get using it as formula in Excel. 这就是我在Excel中将其用作公式的方式。 Note the difference in the Len of strings: 请注意弦线长度的差异:

在此处输入图片说明

Hope this helps 希望这可以帮助

You have characters that look like a space character, but are not. 您有看起来像空格字符的字符,但不是。 They are UniCode 8236 & 8237. 它们是UniCode 8236和8237。

Just replace them with a space character (ASCII 32) . 只需将它们替换为空格字符(ASCII 32)即可

EDIT#1: 编辑#1:

Based on the string in your post, the following VBA macro will replace UniCode characters 8236 amd 8237 with simple space characters: 根据帖子中的字符串,以下VBA宏将用简单的空格字符替换UniCode字符8236和8237:

Sub Kleanup()
Dim N1 As Long, N2 As Long
Dim Bad1 As String, Bad2 As String

N1 = 8237
Bad1 = ChrW(N1)
N2 = 8236
Bad2 = ChrW(N2)

Cells.Replace what:=Bad1, replacement:=" ", lookat:=xlPart
Cells.Replace what:=Bad2, replacement:=" ", lookat:=xlPart

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM