作者:乔山办公网日期:
返回目录:excel表格制作
按ALT+F11,调出VBA窗口,在左上角的工程窗体空白处点击右键——插入zhidao——模块,左回边窗口中复制以下内容:
Function SumColor(rColor As Range, rSumRange As Range)
Application.Volatile
iCol = rColor.Interior.ColorIndex
For Each rCell In rSumRange
If rCell.Interior.ColorIndex = iCol Then
vResult = WorksheetFunction.Sum(rCell) + vResult
End If
Next rCell
SumColor = vResultEnd Function
关闭VBA窗口回到excel,假设你的数答据在A列,B1输入
=sumcolor(A1,A1:A15)
计算结果是A1:A15中颜色为A1单元格底色的数据之和。
添加新来的源函数zd
Function SumColor(rColor As Range, rSumRange As Range)
Application.Volatile
iCol = rColor.Interior.ColorIndex
For Each rCell In rSumRange
If rCell.Interior.ColorIndex = iCol Then
vResult = WorksheetFunction.Sum(rCell) + vResult
End If
Next rCell
SumColor = vResult
End Function
比如 a1 是条件区域
a2 输入公式 =countif(b:b,a1)*a1 假如 我们要求和zd的区域 在 b:b 可以自回己改动
颜色
点击b1 点击格式 条件格式 输入公式 =$a$1 设置颜色 格式刷 刷一下答 b列 就可以了
可以筛选出来求和 或者用辅助列,定义名称=GET.CELL(63,A1),把单元格颜色代表的数字求出来,再sumif 用好几个辅助列!! 用VBA应该也可以