vba Excelmacro 使用不同工作表中指定的值搜索和替换单元格值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3571747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excelmacro to search and replace cellvalues with values specified in a different sheet
提问by user204245
I found this, but it doesn't work. Not sure what I am doing wrong.
我找到了这个,但它不起作用。不知道我做错了什么。
In Sheet 1 I want to search and replace certain terms.
在工作表 1 中,我想搜索和替换某些术语。
Such as WH with White, PK with Pink, TT with Two Tone, YE with Yellow and so on.
比如WH配白色,PK配粉色,TT配两色,YE配黄色等等。
I have a list in sheet three with what to find in one column and what to replace in the same row in the next column.
我在第三张表中有一个列表,其中包含要在列中查找的内容以及在下一列的同一行中替换的内容。
Now I want to use those values and run it through a macro and replace them in sheet 1.
现在我想使用这些值并通过宏运行它并在工作表 1 中替换它们。
Thanks,
谢谢,
Can any one help me correct this code or help test it.
Sub multiFindNReplace()
Dim myList, myRange
Set myList = Sheets("sheet3").Range("A8:B10") 'two column range where find/replace pairs are
Set myRange = Sheets("sheet3").Range("D1:F100") 'range to be searched
For Each cel In myList.Columns(1).Cells
myRange.Replace what:=cel.Value, replacement:=cel.Offset(0, 1).Value
Next cel
End Sub
回答by user431948
I think the second Sheet3 is just a typo:
我认为第二个 Sheet3 只是一个错字:
Set myRange = Sheets("sheet1").Range("D1:F100")
range to be searched
Set myRange = Sheets("sheet1").Range("D1:F100")
要搜索的范围