代码如下:
Sub 替换()
' 表制作循环sheet页变量
i = 2
' 词根循环变量
j = 2
'替换后字符串
replaceStr = ""
'判断字符串是否在词根存在
ifExists = 0
'判断表制作sheet页的单元格是否为空,不为空才遍历
Do While Not IsEmpty(Cells(i, 1))
' 单元格的值赋值给变量
fromStr = Cells(i, 1)
'字符串按照空格拆分
fromArray = Split(fromStr, " ")
'MsgBox ("The Value of i is : " & fromArray & i)
' 遍历数组
For x = 0 To UBound(fromArray)
fromStr = fromArray(x)
'MsgBox fromArray(x)
j = 2
' 判断词根sheet页的单元格是否为空
Do While Not IsEmpty(Worksheets("词根").Cells(j, 1))
'将需要比较的单元格赋值
compareStr = Worksheets("词根").Cells(j, 1)
'将需要替换的单元格赋值
toStr = Worksheets("词根").Cells(j, 3)
' 如果比较字符串和源字符串