首页 > 解决方案 > 如何在有动态输入和动态输出的地方重复“替换”命令?

问题描述

我正在尝试替换 625 个方程中的系数。

我正在尝试替换

这是我的代码。

Sub FindReplaceAll()

    Dim sht As Worksheet
    Dim fnd As Variant
    Dim rplc As Variant

    'To Replace the x(2) with x(1) and x(2) with x(1) and .... x(625) with x(624)

    For k = 2 To 625       
        fnd = "x(k)"
        rplc = "x(k-1)"
        For Each sht In ActiveWorkbook.Worksheets
            sht.Cells.Replace What:=fnd, Replacement:=rplc, _
                              LookAt:=xlPart, SearchOrder:=xlByRows, 
                              MatchCase:=False, _
                              SearchFormat:=False, ReplaceFormat:=False
        Next sht
    Next k

End Sub

标签: excelvba

解决方案


推荐阅读