|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 供暖季()
Dim arr, brr, i As Integer, j As Integer, k As Integer, sum As Single, sum2 As Single
arr = Range("A1").CurrentRegion.Value
For i = 2 To UBound(arr)
If arr(i, 1) >= #1/1/2001# And arr(i, 1) <= #3/15/2001# Then
j = j + 1
sum = sum + arr(i, 2)
End If
If arr(i, 1) >= #11/15/2001# And arr(i, 1) <= #12/31/2001# Then
k = k + 1
sum2 = sum2 + arr(i, 2)
End If
Next i
ReDim brr(1 To 3, 1 To 2)
brr(1, 1) = arr(1, 1): brr(1, 2) = arr(1, 2)
brr(2, 1) = "2001/1/1至2001/3/15": brr(3, 1) = "2001/11/15至2001/12/31"
brr(2, 2) = VBA.Round(sum / j, 2): brr(3, 2) = VBA.Round(sum2 / k, 2)
Range("F1").CurrentRegion.ClearContents
Range("F1").Resize(3, 2).Value = brr
Cells.Columns.AutoFit
End Sub |
|