Excel VBA根据条件格式的内部颜色隐藏行

时间:2017-03-07 19:13:16

标签: excel vba excel-vba conditional-formatting

我试图在特定单元格状态"是"时隐藏行。那部分完成了。要隐藏的行是包含内部颜色RGB(253,233,217)的行。但是,这种颜色是由于条件格式(彩色的单元格是周末)而出现的,而我的VBA代码命令它们在命令时隐藏它们不会拾取内部颜色。有什么理由吗?我相信我看到了一个特殊的命令,它通过条件格式调用内部颜色,但我似乎无法找到它/弄清楚它。

我的代码:

Sub HideRows()
  Dim beginRow As Long, endRow As Long, chkCol As Long, 
  chkCommCol As Long, rowCnt As Long

beginRow = 1
endRow = Cells(Rows.Count, 1).End(xlUp).Row '<--| set 'endRow' to column A last not empty cell row index
chkCol = 1
chkCommCol = 17

Rows.EntireRow.Hidden = False 'unhides all rows. Subsequent code will hide relevant ones

If Cells(3, chkCommCol).Value = "Yes" Then '<--| if Q3 value is "Yes"
    For rowCnt = beginRow To endRow '<--| loop through the "limit" rows indexes
        With Cells(rowCnt, chkCol) '<--| reference current cell to be cheked
            .EntireRow.Hidden = (.Interior.Color = RGB(253, 233, 217)) '<--| set its corresponding Row 'Hidden' property to True if currently referenced cell has wanted color
        End With
    Next
End If

End Sub

0 个答案:

没有答案