麻烦VBA编程语言的大神帮忙编写编程代码,使EXCEL中对有填充颜色的行进行求和
答案:2 悬赏:0 手机版
解决时间 2021-01-31 06:07
- 提问者网友:寂寞梧桐
- 2021-01-31 00:59
对数据区域有删行或增加行的情况下公式不受影响,
最佳答案
- 五星知识达人网友:春色三分
- 2021-01-31 01:48
对所有 非白 填充颜色单元格求和:
Function mySum(Area As Range)
Dim i&
With Area
For i = 1 To .Count
If .Cells(i).Interior.Color <> &HFFFFFF And IsNumeric(.Cells(i)) Then _
mySum = mySum + .Cells(i)
Next i
End With
End Function
Function mySum(Area As Range)
Dim i&
With Area
For i = 1 To .Count
If .Cells(i).Interior.Color <> &HFFFFFF And IsNumeric(.Cells(i)) Then _
mySum = mySum + .Cells(i)
Next i
End With
End Function
全部回答
- 1楼网友:枭雄戏美人
- 2021-01-31 03:15
你只要选择单元格区域,它会给你统计出来。
Sub 颜色单元格求和()
Dim rg As Range
Dim r0, c0 As Long '初始行列
Dim rc, cc As Long '区域数行列数统计
Dim r, c As Long '行列数循环
Dim s As Integer
DoEvents
Set rg = Application.InputBox("请用鼠标选择数据单元格或者键入单元格地址", "提示", Type:=8)
rg.Select
rc = Selection.Rows.Count
cc = Selection.Columns.Count
r0 = Selection.Row
c0 = Selection.Column
For r = r0 To r0 + rc - 1
For c = c0 To c0 + cc - 1
If Cells(r, c).Interior.ColorIndex <> -4142 Then
s = s + Cells(r, c)
End If
Next c
Next r
MsgBox "你选择的区域有背景颜色的单元格的和为: " & s, vbInformation
End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯