vba 查找和替换公式中的文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21404605/
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
Find and replace text in a formula
提问by Jazz
I'm having trouble understanding how to make a macro.
我无法理解如何制作宏。
I'm trying to search down a column, and in each cell check for the text "TODAY()"
, and replace it with "TODAY() + B2"
where B2 is some number of days.
我试图向下搜索一列,并在每个单元格中检查 text "TODAY()"
,并将其替换为"TODAY() + B2"
B2 是一些天数。
I've been searching and I think I'm close but I'm still having trouble.
我一直在寻找,我想我已经接近了,但我仍然遇到了麻烦。
Sub findrep()
Dim Findtext As String
Dim Replacetext As String
Findtext = "TODAY()"
Replacetext = SUM(TODAY(),"Sheets("Sheet1").Range("B2").Value")
Columns("A").Replace what:=Findtext, replacement:=Replacetext, lookat:=xlPart, MatchCase:=False
End Sub
I'm wanting to show the date in the cell sometime in the future depending on the number of days in cell B2. The VBA has to be able to search through the formula in the cell as there is more than just "TODAY()"
in the formula.
我想在未来某个时候根据单元格 B2 中的天数在单元格中显示日期。VBA 必须能够搜索单元格中的公式,因为不仅仅是"TODAY()"
公式。
Thanks in advance.
提前致谢。
采纳答案by Dmitry Pavliv
Try to change this line
尝试更改此行
Replacetext = SUM(TODAY(),"Sheets("Sheet1").Range("B2").Value")
to
到
Replacetext = "TODAY()+Sheet1!B2"