2017-06-02 115 views
0

我正在处理大型数据文件。 Excel表格的B列包含文件名称。然而,在下载过程中,2个字符会被替换(ä变成+ñ,ö变成+)。我需要能够使用这些文件名进行搜索,因此我需要将名称反转为原始。用unicode字符替换字符

这是我最初试图:

Private Sub scandit(n As Long) 

Dim i As Long 
For i = 2 To n 
Dim a As String 
Dim b As String 
Dim c As String 
Dim d As String 
a = "+" & ChrW(194) ' + 
b = ChrW(132) 'ä 
c = "+" & ChrW(164) ' +n 
d = ChrW(148) 'ö 

    If Not IsEmpty(Cells(i, 2).Value) Then 
     Cells(i, 2).Value = Replace(Cells(i, 2).Value, c, b) 
     Cells(i, 2).Value = Replace(Cells(i, 2).Value, a, d) 
    End If 
Next i 

End Sub 

然而,这是行不通的。 “+ñ”只能被删除但不能被替换。 “+”没有任何反应。

一些google搜索后,我发现这一点:

Sub CommandButton1_Click() 
    Dim fnd As Range 
    With ActiveSheet 
     .Cells.Replace what:="+" & ChrW(194), replacement:=ChrW(132), 
lookat:=xlPart 
     .Cells.Replace what:="+" & ChrW(164), replacement:=ChrW(148), 
lookat:=xlPart 
    End With 
End Sub 

这有完全相同的问题,因为我自己的代码。

例在更换时应如何工作的:SY +广告+ N - >syödä

这将不胜感激,如果有人对如何在这里进行一些想法(请注意,我想要做的仅更换了细胞B中列)。

回答

0

我只是改变了CHRW价值和你的代码开始工作

Sub scandit() 

Dim i As Long 
For i = 2 To 5 
Dim a As String 
Dim b As String 
Dim c As String 
Dim d As String 
a = "+" & ChrW(194) ' + 
b = ChrW(228) 'ä 
c = "+" & ChrW(241) ' +n 
d = ChrW(246) 'ö 

    If Not IsEmpty(Cells(i, 2).Value) Then 
     Cells(i, 2).Value = Replace(Cells(i, 2).Value, c, b) 
     Cells(i, 2).Value = Replace(Cells(i, 2).Value, a, d) 

    End If 
Next i 

End Sub 
+0

达姆我必须missread表我所用。谢谢! – Alluton