简单的VBA循环与求解器
我在VBA中有以下macros,我试图让它工作,但我得到一个错误:“编译错误:对象必需”
Sub Macro6() ' Macro6 Macro Dim counts As Integer Set counts = 27 Do While counts < 28 SolverOK SetCell:=Sheets("Slag Case_forcedConvection").Cells(counts, 66), MaxMinVal:=3, ValueOf:=1, ByChange:=Sheets("Slag Case_forcedConvection").Cells(counts, 32) SolverSolve userfinish:=True counts = counts + 1 End Sub
VBA Do While Loop的正确语法是
Do While *Condition* CODE Loop
你错过了底部的“循环”。
整数/长整数不需要设置,只需要定义。 对象和范围需要set命令。
当你使用Integer时,你应该删除Set
Set counts = 27
。
如果仍然出现错误,最好使用F8(或者中断/暂停代码)来查看代码,以确定发生了哪些线路错误。
http://www.vbtutor.net/提供了一些很好的教程,以便在需要对VB编码进行扎实的介绍的情况下开始。 我希望这有帮助…