IfBolThenTotal = Total + Rg.ValueEndIfNext按颜色求和 = TotalEndFunction Function按颜色计数(iAsRange, jAsRange)'新建一个自定义函数,函数名为 Countc(参数 1 是一个区域 i,参数 2 也是一个区域 j)Dim n As Integer '定义一个变量 n,变量 n 为数值Dim kAsRange'定
Public Function ColorChange()For i = 2 To Cells(1000, 2).End(xlUp).RowIf Cells(i, 2).Interior.Color = 12611584 ThenColorChange = "配料"Exit FunctionEnd IfNextColorChange = ""End Function判断单元格的颜色,现在只能使用vba呢。函数不能判断单元格的颜色。用IF 判断啊
If rng.Interior.ColorIndex = col.Interior.ColorIndex Then SumColor = Application.Sum(rng) + SumColor End If Next rng End Function 这样的话,我们单元格里面输入公式:=SumColor(B2:D14,B3)我们用代码自定义了一个求和函数,第一个参数是求和区域,第二个参数是求和的颜色参照单元格 VBA代码的方法,当...
(2)在插入的模块中输入如下代码(可以复制此处代码进行粘贴。能实现颜色求和功能的代码有多种,下方只是相对简单的一种。) Function SumColor(sum_range As Range, ref_rang As Range) Dim x As Range For Each x In sum_range If x.Interior.ColorIndex = ref_rang.Interior.ColorIndex Then SumColor = Applic...
If x.Interior.Color = s Then n = n + x.Value End If Next YS = n End Function 2.1输入自定义公式:在C10单元格输入刚刚的自定义公式“=YS(B10,$B$2:$J$8)”2.2 函数解释: YS(颜色对象,求和区域) 即计算在B2:J8区域内颜色与B11单元格相同的所有数字的和。按对应颜色的条件求和:上面介绍...
If icell.Interior.ColorIndex = col.Interior.ColorIndex Then SumColor = Application.Sum(icell) + SumColor End If Next icell End Function 解析:SumColor是自定义的函数名称,里面包括两个参数,第一参数col是要获取颜色的单元格,第二参数sumrange是求和区域。(这里相当于我们自己创建一个函数SumColor,并且...
Function SumColor(sum_range As Range, ref_rang As Range) Dim x As Range For Each x In sum_range If x.Interior.ColorIndex = ref_rang.Interior.ColorIndex Then SumColor = Application.Sum(x) + SumColor End If Next x End Function
.Color = -16776961 .TintAndShade = 0 End With End If Next myCell End Sub The color value of your RGB values = 10284031 (i.e. the result of R+G*256+B*256*256). You need this to be able to read out color value in each of your cells. ...
If x.Interior.ColorIndex = ref_rang.Interior.ColorIndex Then SumColor = Application.Sum(x) + SumColor End If Next x End Function (3)返回工作表即可用函数SUMCOLOR进行求和了。 附上代码解析: 注意:使用了宏表函数,以及VBA自定义函数后,文件需要保存为支持宏的xlsm格式。 小结 1.如果是利用条件格式赋予...
EachRgIn求和区域SelectCase颜色类型Case"填充"Bol = (Rg.Interior.Color = 参考单元格.Interior.Color)Case"字体"Bol = (Rg.Font.Color = 参考单元格.Font.Color)CaseElse按颜色求和 ="第三参数出错,请检查确认"ExitFunctionEndSelectIfBolThenTotal = Total + Rg.ValueEndIfNext按颜色求和 = TotalEndFunction...