You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VBA中实现运行SelectAcct后单元格为0则跳过ProduceInv?

实现需求的修改方案

直接在调用SelectAcct后增加条件判断,当指定单元格值为0时跳过ProduceInv,进入下一次循环。修改后的VBA代码如下:

Sub AutoMakeInv()

    Dim lPrefix As Long
    Dim lCount As Long
    Dim Account_Number As String

    For lPrefix = 1 To 14
        For lCount = 1 To 2000
            ' 定义循环跳转标签
NextLoop:
            Account_Number = "F" & Format(lPrefix, "00") & " " & Format(lCount, "0000")
            Debug.Print Account_Number
            Cells(8, 5).Value = Account_Number
            Call SelectAcct
            
            ' 把这里的Cells(1,1)替换成你实际要检查的指定单元格
            If Cells(1, 1).Value = 0 Then
                GoTo NextLoop ' 跳过ProduceInv,直接进入下一轮循环
            End If
            
            Call ProduceInv
            ' Do something ...
        
        Next lCount
    Next lPrefix

End Sub

关键说明

  • VBA没有原生的Continue For语句,这里用GoTo配合标签NextLoop实现跳过本次循环剩余代码的效果
  • 条件判断要放在SelectAcct调用之后,确保是调用该过程后的单元格值触发判断
  • 一定要把示例中的Cells(1,1)替换成你实际需要检查的单元格地址,比如Range("C5")或者Cells(10, 3)这类格式

内容的提问来源于stack exchange,提问作者lnzxl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 19:31:14