range.replace方法不起作用

这是我想要做的:

  • 根据表1中的列表replacesheet15 column Dsheet15
  • 在表1中, col A列出了我想要replace的单词列表,而我想用它replace的相应单词旁边是它( col B

下面的代码工作正常,当我尝试在一个新的工作簿,但是当我把它放在我的项目,它不。 我一行一行的debugging,没有错误,但没有相应的文字被replace。

我无法弄清楚什么是错的。 这里有人知道我哪里错了吗?

 sub changeproc() Dim fromVal As String, toVal As String, cel As Range, lr As Long With Sheet1 'validation list and replacement lr = .Cells(.Rows.Count, 1).End(xlUp).Row For Each cel In .Range("A1:A1" & lr) 'ori list in col a fromVal = cel.Value2 toVal = cel.Offset(0, 1).Value2 'replacement list in col b 'Sheet15.Range("D:D").Replace fromVal, toVal, xlWhole, , True 'replace at data sheet Next End With End Sub 

代码是好的,只要确保你使用正确的表名。 检查VBA项目,或确保使用表格(“name_here”)。

和(可能很明显,但只是要确定:P)取消注释此行: 'Sheet15.Range("D:D").Replace fromVal, toVal, xlWhole, , True 'replace at data sheet