Reputation: 101
I keep getting this error in my code:
Sub Button2_Click()
Dim start As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim amount As Integer
amount = 0
Dim answer As Range
Set answer = Range("K22:K28")
For k = Range("K22").Row To Range("K28").Row
For j = Range("B11").Row To Range("B371").Row Step 7
amount = amount + j
Next
k = amount
amount = 0
Next
End Sub
What I'm trying to do in this code is to loop through every 7 instances of the B column, get their value and sum them together, store the sum at the cells starting K22 and start the loop again from the next B cell following, in this case B12, with B12's sum to be stored in K23 and so forth. What am I doing wrong here? Please let me know, any pointers to the right direction would be great.
I'm trying to make a button for this, when clicking the button will run through my program and start calculating and displaying.
Upvotes: 1
Views: 1621
Reputation:
This is what I believe you were writing.
Sub Button2_Click()
Dim b As Long, k As Long
Dim amount As Double
For k = 22 To 28
For b = 11 + (k - 22) To 371 + (k - 22) Step 7
amount = amount + Range("B" & b)
Next b
Range("K" & k) = amount
amount = 0
Next k
End Sub
After changing it in the VBE use Alt+Q to return to your worksheet.
Upvotes: 2