VBA

时间:2016-05-18 07:31:02

标签: excel vba

我在循环中使用平均函数,它计算每个月同一客户的金额平均值(不是月平均值,只考虑开放天数),它在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

0 个答案:

没有答案