I can't figure out why I am getting this error or how to correct it, any thoughts? TThe error is occuring in the line:
If Range("PaymentAmount").Offset(i, 0) = "Cash" Then
Sub Calculation()
Dim r As Range, CashAvg As Double, CheckAvg As Double, CreditAvg As Double
Dim CashSum As Double, CashCount As Integer, CheckSum As Double, CheckCount As Integer, CreditSum As Double, CreditCount As Integer
Set r = Range(Range("I2"), Range("I2").End(xlDown))
With ThisWorkbook.Worksheets("Problem3")
For i = 1 To r.Rows.Count
If Range("PaymentAmount").Offset(i, 0) = "Cash" Then
CashSum = CashSum + Range("I").Offset(i, 1)
CashCount = CashCount + 1
ElseIf Range("I").Offset(i, 0) = "Check" Then
CheckSum = CheckSum + Range("I").Offset(i, 1)
CheckCount = CheckCount + 1
ElseIf Range("I").Offset(i, 0) = "Credit" Then
CreditSum = CreditSum + Range("I").Offset(i, 1)
CreditCount = CreditCount + 1
End If
Next i
End With
If CashSum > 0 And CashCount > 0 Then
CashAvg = CashSum / CashCount
Else
CashAvg = 0
End If
If CheckSum > 0 And CheckCount > 0 Then
CheckAvg = CheckSum / CheckCount
Else
CashAvg = 0
End If
If CreditSum > 0 And CreditCount > 0 Then
CreditAvg = CreditSum / CreditCount
Else
CreditAvg = 0
End If
MsgBox "CashAvg = " & CashAvg & " CheckAvg = " & CheckAvg & " CreditAvg = " & CreditAvg
End Sub
Bookmarks