2017-07-14 35 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