VBA如果对于语句 – 下一步

我试图设置这个macros,所以如果一个单元格等于“未完成”,它将跳到我的下一个indx 。 我遇到的问题是我必须使用一个不同的variables,它只会运行For语句并结束macros。

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

这是我在macros观开始时所build立的:

  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 

你想要这个:

 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 

我认为这里的循环是错位的。

如果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