VBA计算与颜色和特定文本匹配的单元格

时间:2018-08-21 03:05:52

标签: excel vba excel-2016

我正在尝试获取VBA代码,以根据单元格填充颜色和其中的文本来匹配范围内的单元格。

我一次很容易就能获得一个条件,但是每次尝试组合条件时,我都会遇到VALUE错误。请帮忙!

这就是我拥有的:

  • G23-100是范围
  • F19是要匹配的颜色和文字

Function CountColorValue()
    Dim text As String
    Dim cell As Range
    For Each cell In Range("G23:G210")
        If cell.Interior.ColorIndex = Range("F19").Interior.ColorIndex Then
            If cell.text Like Range("F19").text Then
                text = text + 1
            End If
        End If
    Next cell
    Cells(1, 2).Value = numbers
End Function

它不起作用,所以我在这里。 预先感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您的函数实际上不是函数,而是例程,因为您没有输出。您有多个错误我已尝试解决,但没有解决,应该可以,如果可以,请在左上角将其标记为正确答案

Function CountColorValue() as integer
    Dim iColor as long, cnt as long
    Dim text As String, str as string
    Dim cell As Range
    iColor=Range("F19").Interior.ColorIndex
    str=Range("F19").value

    For Each cell In Range("G23:G210")
        If cell.Interior.ColorIndex = iColor and cell.text Like str  Then
            cnt=cnt+1
        End If 
     Next cell

     CountColorValue=cnt
 End Function

答案 1 :(得分:0)

根据我的测试,请尝试以下VBA代码:

<html>
  <svg width="300" height="300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">    
     <defs>      
        <radialGradient id="gradient_toaster">
          <stop offset="100%" stop-color="#804e0f" stop-opacity="100%" />
          <stop offset="0%" stop-color="#3b003b" stop-opacity="100%" />
        </radialGradient>

        <filter id="toaster">
          <feFlood flood-color="#gradient_toaster" flood-opacity="0.5" />
          <feBlend mode="screen" in="SourceGraphic" />
        </filter>
     </defs> 

      <rect x="0" y="0" width="300" height="300" filter="url(#toaster)" fill="gray"/>        
  </svg>
</html>

希望它对您有所帮助。