Excel VBA:通过匹配非活动工作表隐藏假日行

时间:2017-03-16 14:31:05

标签: excel vba excel-vba

我试图隐藏包含假日日期的行。在另一个模块中,我在单元格R3中有命令“yes”来激活这个子,所以我只需要弄清楚sub。没有错误,它只是不隐藏我需要隐藏的行。我正在使用的公式用于查找假期,因为当我将其放入条件格式时,它正确地突出显示了单元格。代码如下:

Sub HideHolidays()

Dim beginRow As Long, endRow As Long, chkCol As Long, chkCommCol As Long, rowCnt As Long

Application.ScreenUpdating = False
beginRow = 4
HolidaybeginRow = 2
endRow = ActiveWorkbook.Sheets("2017 All Districts").Cells(Rows.Count, 1).End(xlUp).Row '<--| set 'endRow' to column A last not empty cell row index
chkCol = 1
chkCommCol = 17
chkHolCol = 18
'Set Sheets("2017 All Districts").Range(beginRow, chkCol).FormulaR1C1 = "=Match($A1,Holidays!$B$2:$B$11,0)"

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

If Cells(3, chkHolCol).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
            If ActiveCell.FormulaR1C1 = "=Match($A1,Holidays!$B$2:$B$11,0)" Then
                Application.EntireRow.Hidden
            End If
        End With
    Next
End If
Application.ScreenUpdating = True

End Sub

0 个答案:

没有答案