我希望通过VBA代码计算一年中每个月的多个列的平均值,而不必除以每个月的周数。有人可以帮我弄清楚我必须在我的代码中插入平均值吗?
Private Sub CALCULATE_BTN_Click()
Dim DBS As Database
Dim RST As Recordset
Dim SQL_TXT As String
Range("AA9:BV10").Select
Selection.Clear
If OPEN_DBS(DBS, FUEL_DB) Then
SQL_TXT = "SELECT * FROM FUEL_DATA"
If OPEN_RST(DBS, RST, SQL_TXT) Then
While Not RST.EOF
For i = 1 To 12
If Month(RST![FUELDATA_DATE]) = Month(Cells(8, 26 + i).Value) And Year(RST![FUELDATA_DATE]) = Year(Cells(8, 26 + i).Value) Then
Cells(9, 26 + i).Value = Cells(9, 26 + i).Value + RST![FUELDATA_AUTOMOTIVE] / 9 / 1000
End If
Next i
RST.MoveNext
Wend
RST.Close
End If
DBS.Close
End If
End Sub