2016-08-15 98 views
-1

我明白,最常見的情況是,當出現未終止的情況時會發生此錯誤,但我似乎無法找到它。我是Excel VBA的完整初學者,請耐心等待。這是我的代碼。基本上,這個宏的要點是讀取a9和b9中選定的值對,然後搜索結果列表,直到它與a9和b9中的值相對應,然後將1添加到該特定行的列中。編譯錯誤:無循環

Dim z As Integer 
z = 42 
'If selected adc = adc in row z 
' Then if selected sp = sp in row z 
'Add 1 to win column in row z 

If [a9] = [g[z]] Then 
    If [b9] = [h[z]] Then 
    [i[z]] = [i[z]] + 1 
    End If 

    'Elseif selected adc =/= adc in row z 
    'Then add 1 to row 
    'Do until selected adc = adc in row z 

ElseIf [a9] <> [g[z]] Then 
    z = z + 1 
    Do Until [a9].Text = [g[z]].Text 
    Exit Do 

    'If selected sp = sp in row z 
    'Then add 1 to column h (win column) in row z 

    If [b9] = [h[z]] Then 
     [i[z]] = [i[z]] + 1 
    End If 

    'If selected sp =/= sp in row z 
    'Then add 1 to row 
    'Do until selected sp = sp in row z 

    If [b9] <> [h[z]] Then 
     z = z + 1 
     Do Until [b9].Text = [h[z]].Text 
     Exit Do 
     If [b9] = [h[z]] Then 
      [i[z]] = [i[z]] + 1 
     End If  
+1

這和錯誤告訴你的一樣:「你的'Do'沒有'Loop'。」 ('Exit Do'就像'Exit For'不是聲明結尾的替代品) –

回答

1

在你有做,直到立即退出,接着做底層,這意味着做不會發生,但還是語法,你需要有一個循環後做標記循環的結束。