Hi, I´ve been trying to loop through a column range and sum a line offset range on the right of cell in the loop range. It is suppose to sum if a if statement is true but it seems like I´m getting true when actually false and therefore it sums every range.
My code is as follows:
Sub summoff()
Dim sum1 As Double
Dim sum2 As Double
Dim A As Range
Dim r As Range
Dim r1 As Range
Set r1 = Range("K475:k480")
sum2 = 0
For Each r In r1
If r.Value = 6200 Or 62001 Then
r.Offset(0, 11).Select
Set A = Selection.Resize(1, 12)
sum1 = Application.WorksheetFunction.Sum(A)
sum2 = sum2 + sum1
sum1 = 0
End If
Next
MsgBox sum2
End Sub
range K475:k480 is:
k475 blank
k476 6
k477 blank
k478 6200
k479 62001
k480 6450
offset contains various numbers.
Can anybody point out to me the right way to do this ?
Thank you.
Eric
My code is as follows:
Sub summoff()
Dim sum1 As Double
Dim sum2 As Double
Dim A As Range
Dim r As Range
Dim r1 As Range
Set r1 = Range("K475:k480")
sum2 = 0
For Each r In r1
If r.Value = 6200 Or 62001 Then
r.Offset(0, 11).Select
Set A = Selection.Resize(1, 12)
sum1 = Application.WorksheetFunction.Sum(A)
sum2 = sum2 + sum1
sum1 = 0
End If
Next
MsgBox sum2
End Sub
range K475:k480 is:
k475 blank
k476 6
k477 blank
k478 6200
k479 62001
k480 6450
offset contains various numbers.
Can anybody point out to me the right way to do this ?
Thank you.
Eric