首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅使用VBA选择可见单元格的范围

仅使用VBA选择可见单元格的范围
EN

Stack Overflow用户
提问于 2018-10-04 02:28:18
回答 1查看 1.8K关注 0票数 0

我想在状态跟踪器上使用以下函数"CountCcolor()“。我的意图是能够使用该函数在单个列中查找可见单元格的范围,以特定颜色高亮显示多少,比如绿色。

代码语言:javascript
复制
Function CountCcolor(range_data As Range, criteria As Range) As Long

    Dim datax As Range
    Dim xcolor As Long

    ' The next one-liner does not work. Without it, it selects visible and hidden cells. I only want it to select visible cells:
    range_data = Selection.SpecialCells(xlCellTypeVisible).Select

    xcolor = criteria.Interior.ColorIndex
    For Each datax In range_data
        If datax.Interior.ColorIndex = xcolor Then
             CountCcolor = CountCcolor + 1
        End If
    Next datax
End Function

谢谢你提前提供帮助!

EN

回答 1

Stack Overflow用户

发布于 2018-10-04 02:44:20

不要使用Interior.ColorIndex

相反,只需使用Interior.Color。我也曾被这件事困扰过一次。简而言之,ColorIndex代表的是颜色的味觉,而不是是独特的颜色。有关更多细节,请参见here

代码语言:javascript
复制
Function CountCcolor(range_data As Range, criteria as Range) As Long

Dim myRange As Range, myCell As Range, TempCount As Long
Set myRange = range_data.SpecialCells(xlCellTypeVisible)

For Each myCell In myRange
    If myCell.Interior.Color = criteria.Interior.Color Then
        TempCount = TempCount + 1
    End If
Next myCell

CountCcolor = TempCount

End Function
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52638119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档