我试图做的事情是,如果vInputs(1, i)
小于22我想要的代码去下一个迭代列,如果它超过22只继续代码。
问题是在If vInputs(1, i)...
线。不知道我做错了:
Sub CreateTestResultTableV2()
Application.ScreenUpdating = False 'helps the code run faster
Dim vInputs, vResults()
Dim c As Integer, i As Integer
'create INPUTS array
c = Range("b5").End(xlToRight).Column
vInputs = Range("b5", Cells(8, c))
'determine last value in the column
c = UBound(vInputs, 2)
'create RESULTS array
ReDim vResults(1 To 3, 1 To c)
For i = 1 To c
If vInputs(1, i) <= 22 Then GoTo Next i
Else
'set values
Range("j16") = vInputs(1, i)
Range("n12") = vInputs(4, i)
'copy output values into RESULTS array
vResults(1, i) = Range("h41")
vResults(2, i) = Range("k41")
vResults(3, i) = Range("z14")
Next i
Range("e47").Resize(3, c) = vResults
Application.ScreenUpdating = True
End Sub
不要使用Goto
语句跳过迭代的循环。使用相对操作者只有在循环时的条件是True
执行代码。
For i = 1 To c
If vInputs(1, i) > 22 Then
'set values
Range("j16") = vInputs(1, i)
Range("n12") = vInputs(4, i)
'copy output values into RESULTS array
vResults(1, i) = Range("h41")
vResults(2, i) = Range("k41")
vResults(3, i) = Range("z14")
End if
Next i