在宏循环中的宏

时间:2014-01-16 16:28:19

标签: vba loops

我正在尝试运行一个循环某些其他宏的宏,但它不起作用。

每个单独的宏都完全符合它们的预期,我已经测试了它们,但是当尝试运行下面的代码时,循环外的第一个宏工作,然后没有其他任何事情发生。

我尝试了各种不同的循环方法(最新版本如下),包括已在本网站发布的方法。

Sub MasterMacro()

Dim EndCriterion As Long
Dim i As Long

Cells.Find(What:="Step", After:=Cells(1, 1), LookAt:=xlPart).Select
Selection.End(xlDown).Select
EndCriterion = ActiveCell.Row

Application.Run "CColumnFind"

For i = 1 To EndCriterion

    Application.Run "Stepper"
    Application.Run "RetrieveIdeal"
    Application.Run "RecompileArray"
    Application.Run "Return"

Next i

Application.ScreenUpdating = False

End Sub

`

1 个答案:

答案 0 :(得分:0)

最好的猜测,但很难说出你的其他宏发生了什么......

Sub MasterMacro()

Dim EndCriterion As Long
Dim i As Long, f As Range

Set f = Cells.Find(What:="Step", After:=Cells(1, 1), LookAt:=xlPart)
If Not f Is Nothing Then
    EndCriterion = f.End(xlDown).Row
Else
    MsgBox "'Step' not found!"
    Exit Sub
End If

CColumnFind

For i = 1 To EndCriterion
        Stepper
    RetrieveIdeal
    RecompileArray
    Return

Next i

Application.ScreenUpdating = False

End Sub