EXCEL-VBA:根据单元格字体、背景颜色计数、求和
来源:互联网 发布:贾巴尔数据 编辑:程序博客网 时间:2024/06/05 12:26
1、EXCEL-开发工具中Visual Basic
2、Sheet1上右键插入模块
3、代码粘贴
Function CountByBGColor(Col As Range, CountRange As Range) '根据背景颜色计数Application.Volatile'用于将用户自定义函数标记为易失性函数,无论何时在工作表的任意单元格中进行计算时,易失性函数都必须重新进行计算。'非易失性函数只在输入变量改变时才重新计算,若不用于计算工作表单元格的用户自定义函数中,则此方法无效。Dim iCell As RangeCountByBGColor = 0For Each iCell In CountRange If iCell.Interior.Color = Col.Interior.Color Then CountByBGColor = CountByBGColor + 1 End IfNextEnd FunctionFunction SumByBGColor(Col As Range, SumRange As Range) '根据背景颜色求和Application.VolatileDim iCell As RangeSumByBGColor = 0For Each iCell In SumRange If iCell.Interior.Color = Col.Interior.Color Then SumByBGColor = SumByBGColor + Application.WorksheetFunction.Sum(iCell) End IfNextEnd FunctionFunction CountByFontColor(Col As Range, CountRange As Range) '根据字体颜色色计数Application.VolatileDim iCell As RangeCountByFontColor = 0For Each iCell In CountRange If iCell.Font.Color = Col.Font.Color Then CountByFontColor = CountByFontColor + 1 End IfNextEnd FunctionFunction SumByFontColor(Col As Range, SumRange As Range) '根据字体颜色求和Application.VolatileDim iCell As RangeSumByFontColor = 0For Each iCell In SumRange If iCell.Font.Color = Col.Font.Color Then SumByFontColor = SumByFontColor + Application.WorksheetFunction.Sum(iCell) End IfNextEnd Function
5、四个函数的,第一个参数是格式参照的单元格,第二个参数是求和或计数的区域。
例:=SumByFontColor(J45,M35:P41)
0 0
- EXCEL-VBA:根据单元格字体、背景颜色计数、求和
- excel VBA对特定背景颜色的单元格进行赋值
- EXCEL.VBA应用 非隐藏单元格求和
- EXTJS根据值Value改变gridpanel单元格背景颜色或者设置整行字体颜色
- Excel的单元格根据文字内容改变格式,比如改变单元格的背景颜色
- Excel VBA 根据实际需求合并单元格
- 根据绑定的值的不同改变gridview里某一单元格的字体或背景颜色
- Excel 单元格按照条件改变背景颜色
- POI之Excel自定义单元格背景颜色
- aspxGridview 根据单元格值得不同,设置单元格字体的颜色
- vba为每行中最小值单元格添加背景颜色
- vba为每行中最小值单元格添加背景颜色
- Excel VBA 根据合并单元格大小调整图片大小
- excel vba根据单元格改变时计算其它单元
- 在Excel中根据单元格内容进行计数
- [原创]可改变单元格字体和背景颜色的CListCtrl
- Excel VBA 单元格信息
- Excel VBA 单元格格式
- (解决)android不同版本的【沉浸式状态栏】(4.4/5.0/5.1/6.0)
- 纯真IP数据库格式详解
- 融云在移动端获取token(swift)版
- 安装myeclipse
- Java知识点25
- EXCEL-VBA:根据单元格字体、背景颜色计数、求和
- hdu2588(欧拉函数)
- 在Linux平台上搭建EasyDarwin,编译代码并简单部署
- Java关键字之this
- ZooKeeper详解及工作原理
- 从Internet上抓取指定URL的源码的方案(C#)
- Cmake不是内部或外部命令
- css
- CodeForces 598A Tricky Sum