VBA如果For声明 - 下一个

时间:2017-07-14 15:22:07

标签: excel vba excel-vba

我正在尝试设置此宏,以便在单元格等于“未完成”时跳到下一个indx。我遇到的问题是我必须使用另一个变量,它只运行For语句并结束宏。

我需要For声明吗?如果我在标记单元格“未完成”后放置Next Indx则会出错。

这是我在宏开头设置的:

  Dim indx As Integer
  For indx = 4 To 1000
  ordnbr = Sheet1.Cells(indx, 1)
  If Trim(ordnbr) = "" Then
        Exit For
  End If

在下面的代码之前,我有我的if语句......

    Else: Sheet1.Cells(indx, 9) = "Not Competed"
    End If

    For indx = 4 To 6
    If Trim(Status) = "Not Completed" Then
    Next indx
    End If

2 个答案:

答案 0 :(得分:1)

你想要这个:

For indx = 4 To 6
    If Trim(Status) = "Not Completed" Then
        'do nothing, which ultimately causes indx to skip to next in sequence
    Else
        'put some code here to do something, next in sequence will occur naturally
    End If
Next indx

答案 1 :(得分:0)

我认为这里的循环未对齐。

如果Else Endif应该都在For循环中。我修改了一下,如下:

    Sub subname()

     Dim indx As Integer

     a = Sheet1.UsedRange.Rows.Count

        For indx = 4 To a
        ordnbr = Sheet1.Cells(indx, 1)
        If Trim(ordnbr) = "" Then
        Else: Sheet1.Cells(indx, 9) = "Not Competed"
        End If
        Next

    End Sub
相关问题