批量替换 宏

Windows Office Excel 数据字典的批量替换代码:

Sub batchReplace()
'
' 批量替换 宏
'

'字符串声明
 Dim str1 As String
 Dim str2 As String
'两层循环嵌套,i表示行号
 For i = 1 To 500
'拼接An,并取其中的值
    str1 = Sheets("Sheet2").Cells(i, "A").Value
    str2 = Sheets("Sheet2").Cells(i, "B").Value
    Sheets("Sheet1").Select
    Cells.Replace What:=str1, Replacement:=str2, LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
 Next
End Sub
0%