2017-06-02 181 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