教程excel吧 关注:20贴子:85
  • 3回复贴,共1

【VBA】自定义函数收集

取消只看楼主收藏回复

一楼度娘


1楼2013-12-09 23:39回复
    1,按背景颜色统计个数
    Function Countcolor(col As Range, countrange As Range)
    Dim icell As Range
    Application.Volatile
    For Each icell In countrange
    If icell.Interior.ColorIndex = col.Interior.ColorIndex Then
    Countcolor = Countcolor + 1
    End If
    Next icell
    End Function


    本楼含有高级字体2楼2013-12-10 00:29
    回复
      2,按背景颜色求和
      Function Sumcolor(col As Range, sumrange As Range)
      Dim icell As Range
      Application.Volatile
      For Each icell In sumrange
      If icell.Interior.ColorIndex = col.Interior.ColorIndex Then
      Sumcolor = Application.Sum(icell) + Sumcolor
      End If
      Next icell
      End Function


      本楼含有高级字体3楼2013-12-10 00:48
      回复
        3 统计个数,然后在一个单元格内返回结果


        Function test(rng As Range) As String
        Dim dic As Object
        Dim c As Range
        Dim arr, v, k, t
        Set dic = CreateObject("scripting.dictionary")
        arr = rng.Value
        For Each c In rng.Cells
        v = c.Value
        dic(v) = dic(v) + 1
        Next
        k = dic.keys
        t = dic.items
        For i = 0 To UBound(k)
        k(i) = k(i) & t(i)
        Next
        test = Join(k, ",")
        Set dic = Nothing
        End Function


        本楼含有高级字体4楼2013-12-13 20:51
        回复