Reputation:
The thing I am trying to do is if vInputs(1, i)
is less than 22 I want the code to go to the next iteration column and if it's greater than 22 to just continue with the code.
The problem is in the If vInputs(1, i)...
line. Not sure what I am doing wrong:
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
Upvotes: 0
Views: 54
Reputation: 1529
Don't use a Goto
statement to skip iterations in a loop. use the opposite operator and only execute the code in the loop when the conditions are 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
Upvotes: 4