|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 YZC51 于 2020-3-21 19:58 编辑
如下代码实现,【本月合计】与【本年累计】
Public flg
Sub 合计()
Dim LJ, HJ, LJD, HJD
myr = Range("E65536").End(xlUp).Row
flg = 1
For i = 5 To myr
If Len(Cells(i, 2)) Then
LJ = LJ + Cells(i, 8)
HJ = HJ + Cells(i, 8)
LJD = LJD + Cells(i, 19)
HJD = HJD + Cells(i, 19)
End If
If Cells(i, 5) = "" Then Exit For
If Cells(i, 5) = "本月合计" Then
n = i - 1
Range("H" & i) = HJ: HJ = 0
Range("s" & i) = HJD: HJD = 0
Range("AE" & i) = Range("AE" & n)
ElseIf Cells(i, 5) = "本年累计" Then
n = i - 2
Range("H" & i) = LJ
Range("s" & i) = LJD
Range("AE" & i) = Range("AE" & n)
End If
Next
flg = 0
End Sub
|
评分
-
1
查看全部评分
-
|