Reputation: 63
I can't figure out what is the mistake I am making in this code. The error is on setting up the range (line 3 on last loop). Any help would be appreciated. I have lots of code here but i believe all of it is good except in the last loop around p it gives me an error about the range function I believe.
For p = 1 To 100
If ActiveWorkbook.Worksheets(1).Cells(p + 26, 10).Value = Sheet3.Cells(6 + k, 4).Value Then
Set rng = Sheet3.Range(Cells(k + 6, 5), Cells(k + 6, 12))
lAnswer = Application.WorksheetFunction.Sum(rng)
ActiveWorkbook.Worksheets(1).Cells(p + 27, 13).Value = lAnswer
k = k + 1
End If
Next p
End If
Next t
End Sub
Upvotes: 0
Views: 22
Reputation: 34045
You must qualify both Range
and Cells
with the worksheet:
Set rng = Sheet3.Range(Sheet3.Cells(k + 6, 5), Sheet3.Cells(k + 6, 12))
Upvotes: 2