2017-07-14 55 views
0

我想设置这个宏,因此如果一个单元格等于“未完成”,它将跳到我的下一个indx。我遇到的问题是我必须使用不同的变量,它会运行For语句并结束宏。VBA如果对于声明 - 下一步

我需要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 

回答

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 
+0

这就是它感谢您的帮助! –

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