【技巧1001-9】-看完,还不会按颜色求和就是你的不对了

方法2:宏表函数定义名称(GET.CELL)

3、VBA定义函数法


Option Explicit
'作者:Excel办公实战'日期:2019年8月11日Function sumByCol(sum_rng As Range, color_rng As Range) Dim rng As Range, temp_sum Application.Volatile For Each rng In Intersect(sum_rng.Parent.UsedRange, sum_rng) If rng.Interior.ColorIndex = _ color_rng(1).Interior.ColorIndex Then temp_sum = temp_sum + rng.Value End If Next sumByCol = temp_sumEnd Function4、VBA事件智能显示合计

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count <> 1 Then Exit Sub If Target.Interior.ColorIndex <> -4142 Then Range("E1").Resize(1, 2).Clear Range("E1").Interior.ColorIndex = Target.Interior.ColorIndex Range("F1") = sumByCol(Intersect(Target.EntireRow, Target.Parent.UsedRange), Target) End IfEnd Sub
赞 (0)
