Excel本身的查找替换功能非常好用,因为我的工作表的数据是从其他软件导出的,并且导出来是CSV格式的,因此φ这个符号就不能正常显示"n",因此我自己写了个方法去遍历工作簿中的所有工作表。
Sub ReplaceEpeciallyString()
Dim ws As Worksheet
Dim i, j As Integer
Dim findString As String
findString = "xd"
Dim replaceString As String
replaceString = "φ"
Dim cellString As String
Dim findResult As Integer
Dim newString As String
For Each ws In Worksheets
For i = 1 To ws.UsedRange.Rows.Count
For j = 1 To ws.UsedRange.Columns.Count
cellString = ws.Cells(i, j)
findResult = InStr(1, cellString, findString, vbTextCompare)
If findResult > 0 Then
newString = Replace(cellString, findString, replaceString)
ws.Cells(i, j) = newString
End If
Next j
Next i
Next
End Sub
findString 是要替换的字符
replaceString 是替换后的字符
需要注意的是工作表中最好不要有合并的单元格
网友评论