|
<P>office2007就有这个功能了。</P>
<P>2007以前的版本可以用自定义函数,加辅助列的方法来解决。</P>
<P>Function Bcolorsum(y As Range, rng, z As Integer) '背景颜色合计函数<BR>Application.Volatile<BR>Dim c As Double<BR>Dim x As Range<BR>colorsum = 0<BR> For Each x In rng<BR> If x.Interior.ColorIndex = y.Interior.ColorIndex Then<BR> c = x.Offset(0, z).value<BR> Else<BR> c = 0<BR> End If<BR>Bcolorsum = Bcolorsum + c<BR>Next x</P>
<P>End Function<BR>Function Bcolorcount(y As Range, rng) '背景颜色计数函数<BR>Application.Volatile<BR>Dim c As Double<BR>Dim x As Range<BR> For Each x In rng<BR> If x.Interior.ColorIndex = y.Interior.ColorIndex Then<BR> c = 1<BR> Else<BR> c = 0<BR> End If<BR>Bcolorcount = Bcolorcount + c<BR>Next x</P>
<P>End Function</P>
<P>Function Bcolor(color As Range) '注:改变颜色时,公式不能自动更新,需双击任一单元格(或CRTL+ALT+F9)激活公式 。改变单元格数值就不存在这个问题了<BR>Bcolor = color.Interior.ColorIndex<BR>End Function<BR>Function Fcolor(color As Range) '注:改变颜色时,公式不能自动更新,需双击任一单元格(或CRTL+ALT+F9)激活公式 。改变单元格数值就不存在这个问题了<BR>Fcolor = color.Font.ColorIndex<BR>End Function</P> |
|