VBA上的平均function

我在一个循环中使用平均函数,它计算每月同一客户的平均金额(不是月平均值,它只考虑开放date),它在5000行表格上完美工作,用在56703线表,它没有工作得很好,错过了一些客户。 为什么这样做? 我如何解决它

Sub calcav() Dim i As Long Dim j As Long Dim a As Integer Sheets("Source").Activate a = 2 i = 2 While Cells(i, 6) <> "" j = i While Cells(i, 6) = Cells(i + 1, 6) And Month(Cells(i, 18)) =Month(Cells(i + 1, 18)) i = i + 1 Wend Sheets("Average").Cells(a, 1) = Cells(i, 6).Value Sheets("Average").Cells(a, 2) = Month(Cells(i, 18)) Sheets("Average").Cells(a, 3) = Year(Cells(i, 18)) Sheets("Average").Cells(a, 4) =Application.WorksheetFunction.Average(Range("V" & j & ":V" & i)) Sheets("Average").Cells(a, 5) = Left(Cells(i, 20).Value, 3) a = a + 1 i = i + 1 Wend End Sub