【Indirect函数】
利用indirect和data validation来做级联菜单
indirect用法
()非常详细
【sumif&sumifs】
sumif符合两个条件需要用数组公式即CSE
[多重合并数据透视表]
用VBA进行多表合并计算一例
[按颜色排序]
完美Excel
按指定的单元格颜色进行计数或求和 | |||
作者:未知 文章来源: 点击数: 3659 更新时间:2009-6-19 16:45:17 | |||
如果Excel工作表的某区域中包含不同的底纹颜色,我们可以用一个自定义函数对该区域按指定的单元格颜色进行计数或求和。方法是: 1.按Alt+F11,打开VBA编辑器。 2.单击菜单“插入→模块”,将插入名称为“模块1”的模块,在右侧的代码窗口中输入下列代码: Function SumByColor(Ref_color As Range, Sum_range As Range) Application.Volatile Dim iCol As Integer Dim rCell As Range iCol = Ref_color.Interior.ColorIndex For Each rCell In Sum_range If iCol = rCell.Interior.ColorIndex Then SumByColor = SumByColor + rCell.Value End If Next rCell End Function Function CountByColor(Ref_color As Range, CountRange As Range) Application.Volatile Dim iCol As Integer Dim rCell As Range iCol = Ref_color.Interior.ColorIndex For Each rCell In CountRange If iCol = rCell.Interior.ColorIndex Then CountByColor = CountByColor + 1 End If Next rCell End Function上述两个自定义函数,一个是SumByColor,可以对区域按指定单元格的颜色求和。另一个是CountByColor,可以统计区域中某种颜色的个数。这两个自定义函数都有两个参数,前一个参数指定包含某种颜色的单元格,后一个参数为求和或计数区域。 3.关闭VBA编辑器。 使用方法:假如要求和或计数的区域在A1:B10区域中。
求出该区域中单元格底纹颜色为红色的所有单元格数值之和,在单元格中输入公式: =sumByColor(A1,A1:B10) 求出该区域中单元格底纹颜色为红色的所有单元格的个数,在单元格中输入公式: =CountByColor(A1,A1:B10) |
Past Tip of the Day Kári asks, I have a formula where I have to put in a criteria. The criteria is, that the formula has to gather numbers that are bigger than 0,5 (>0,5), but not bigger than 2 (<2). But how do I do that? I have tried: ">0,5"&"<2" and a lot of other combinations, but nothing works.
Kári: For a SUMIF or COUNTIF formula with 2 conditions, you need to use an array formula. This type of formula is discussed here: http://www.mrexcel.com/tip031.shtml.
Since I wrote that article a few years ago, a better version of the formula has come to light. The web page discusses using this formula for a CountIf with 2 conditions:
=SUM(IF($C$2:$C$4403>0.5,IF($B$2:$B$4403<2,1,0),0))You can use boolean logic instead to write this formula for CountIf
=SUM(($C$2:$C$4403>0.5)*($C$2:$C$4403<2)*1) or this formula for SumIf: =SUM(($C$2:$C$4403>0.5)*($C$2:$C$4403<2)*($C$2:$C$4403))Remember, you must hold down the Ctrl and Shift keys then hit enter to enter these CSE or Array formulas.
This tip, and 276 others are in the best-selling book, Learn Excel from MrExcel. You can sign up to receive chapters from this book every Tuesday for free.