The following VB code to reference many excel sheets using index variable in a loop; but I got error

Sum = 0
For i = 1 To 10 Step 1
    Sum = Sum + Sheets(i).Cells(6, 9).Value      
Next i

I'd do it this way in a code module

Option Explicit
Private Sub WkShtSums()
Dim Sum As Integer
Dim i As Integer

For i = 1 To 10
    With ActiveWorkbook.Sheets(i)
        Sum = Sum + .Cells(6, 3).Value
    End With

Next i
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.