Hello,
Is there any special way of using averageifs in VBA - I know I can do it as part of a formula, but it wouldn't work in this situation.
It's always returning a value error when running without the iserror check, even though there is correct data as i tested with a formula.
Any help would be great
Is there any special way of using averageifs in VBA - I know I can do it as part of a formula, but it wouldn't work in this situation.
It's always returning a value error when running without the iserror check, even though there is correct data as i tested with a formula.
Code:
Sub test3p2()
Set ws3 = ThisWorkbook.Worksheets("Test 3")
Set ws2 = ThisWorkbook.Worksheets("Test 2")
Dim i As Integer
Dim x As Integer
i = 1
x = WorksheetFunction.CountA(Columns("A:A"))
Do Until i = x
m = ws3.Range("A" & 1 + i)
Dow = ws3.Range("G2")
sp = ws3.Range("H2")
ep = ws3.Range("I2")
Average = Application.AverageIfs(ws2.Range("D2:D57217"), ws2.Range("A:A"), m, ws2.Range("C2:C57217"), ">=" & sp, ws2.Range("C2:C57217"), "<=" & ep)
If IsError(Average) Then
Average = 0
End If
ws3.Range("B" & 1 + i) = Average
i = i + 1
Loop
End Sub
Any help would be great