如何修改查找/替换以仅引用一个单元格

时间:2019-06-26 03:45:42

标签: vba replace find

我下面有“查找/替换”代码,该代码使用关键字“ Cells”,但结果是更改了工作表中的所有内容。我还无法弄清楚如何使它仅引用一个单元格。

     fnd = " himself "
     rplc = " herself "

     'Perform the Find/Replace All
     sht.Cells.Replace What:=fnd, Replacement:=rplc, _
     LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, _
     SearchFormat:=False, ReplaceFormat:=False

我只需要指代更改一个单元格。它会改变一切。

1 个答案:

答案 0 :(得分:1)

使用此:  将A1更改为您的相应单元格

 fnd = " himself "
 rplc = " herself "

 'Perform the Find/Replace All
 sht.Range("A1").Replace What:=fnd, Replacement:=rplc, _
 LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, _
 SearchFormat:=False, ReplaceFormat:=False