vba 从一列复制到另一列,将整列复制到特定文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16110041/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:44:05  来源:igfitidea点击:

Copy from one column to another , entire column to specific text

excelexcel-vbareplacems-officevba

提问by Rajmakbul

I know this is bit difficult but i wonder if any one can help. I want to copy one entire column data in to other column but When we copy the data , it should only replace one specific word in that column , Not entire content.

我知道这有点困难,但我想知道是否有人可以提供帮助。我想将一整列数据复制到另一列,但是当我们复制数据时,它应该只替换该列中的一个特定单词,而不是整个内容。

For example

例如

Column A    
1234        
5252         
3265         
999        

Column B

This is **

This is **

This is **

This is **

I want to replace Column A data to Column B data but it should only replace ** , So whatever is in the column A will be replaced by ** in Column B , but it should not alter any other text in Column B

我想将 A 列数据替换为 B 列数据,但它应该只替换 ** ,因此 A 列中的任何内容都将被 B 列中的 ** 替换,但不应更改 B 列中的任何其他文本

I wonder if anyone can solve this? Any macro in excel? it is just a find and replace macro but more complicated

我想知道是否有人可以解决这个问题?excel有没有宏?它只是一个查找和替换宏,但更复杂

回答by chuff

Though this could certainly be done in VBA, why not just use a SUBSTITUTE formula? You could then do a Copy/Paste Special to turn the formulas into values. For example, the formula in cell C2 would be =SUBSTITUTE(B2,"****",A2).

虽然这当然可以在 VBA 中完成,但为什么不使用 SUBSTITUTE 公式呢?然后,您可以执行复制/粘贴特殊操作将公式转换为值。例如,单元格 C2 中的公式为=SUBSTITUTE(B2,"****",A2)

enter image description here

enter image description here