查找并替换VBA

时间:2017-10-27 12:11:18

标签: excel vba excel-formula

我有一个从1到90的项目列表。每个项目到第200列的同一行中的所有公式都应该包含链接到正确项目编号的公式。例如:

A1:

Project 1 

B1:

=IFERROR('C:\Users\z003th4b.AD009\Desktop\Gross margin bridges\Projects\[Project (1).xlsm]Nov 17'!$D$3;" ")

C1:

=IFERROR('C:\Users\z003th4b.AD009\Desktop\Gross margin bridges\Projects\[Project (1).xlsm]File_Setup'!$D$17;" ")`

A2:

Project 2 

B2:

=IFERROR('C:\Users\z003th4b.AD009\Desktop\Gross margin bridges\Projects\[Project (2).xlsm]Nov 17'!$D$3;" ")

C2:

=IFERROR('C:\Users\z003th4b.AD009\Desktop\Gross margin bridges\Projects\[Project (2).xlsm]File_Setup'!$D$17;" ")

等等多达90个项目。

目前我正在使用

Sub macro ()
  ActiveCell.Range("A31:BH90").Select
        Selection.Replace What:="Project (1)", Replacement:="Project (2)", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    ActiveCell.Offset(62, 0).Range("A31:BH90").Select

end sub

它似乎不起作用。我是VBA的新手,所以我将不胜感激任何帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

尝试:

Sub Macro ()
  ActiveCell.Range("A1:BH90").Select
        Selection.Replace What:="Project (1)", Replacement:="Project (2)", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    ActiveCell.Offset(62, 0).Range("A1:BH90").Select

End Sub