0

Im writing a code but i get the Invalid Next control variable reference error, and i don't know why. this is my code:

Sub Network()

Dim Net(1 To 8) As Double
Dim Total(1 To 8) As Double
Dim i As Integer


For i = 1 To 8
    For j = 1 To 5

        Net(j) = Worksheets("Summary").Cells((i * 7) + 12, 9).Value

    Next i
Next j



For j = 1 To 5

    Total(j) = WorksheetFunction.Sum(Net(j))

Next j

For j = 1 To 5

    Worksheets("Summary").Cells(73, 8 + j) = Total(j)

Next j


End Sub

hope someone can help me get this error fixed.

1 Answer 1

1

Your i and j variables are the wrong way round, you need to make sure the correct variable is with the correct indentation. Hope this helps!

Sub Network()

Dim Net(1 To 8) As Double
Dim Total(1 To 8) As Double
Dim i As Integer


For i = 1 To 8
    For j = 1 To 5

        Net(j) = Worksheets("Summary").Cells((i * 7) + 12, 9).Value

    Next j
Next i



For j = 1 To 5

    Total(j) = WorksheetFunction.Sum(Net(j))

Next j

For j = 1 To 5

    Worksheets("Summary").Cells(73, 8 + j) = Total(j)

Next j


End Sub
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.