I am trying to hide the rows that contain the dates of holidays. In another module, I have the command "yes" in cell R3 to activate this sub so I just need to figure out the sub. There are no errors, it just doesn't hide the rows I need it to hide. The formula I'm using works to find the holidays because it properly highlights the cells when I put it into Conditional Formatting. Code is below:
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
HIDE WEEKEND CODE: Sub HideWeekends() Dim beginRow As Long, endRow As Long, chkCol As Long, chkCommCol As Long, rowCnt As Long
Application.ScreenUpdating = False
beginRow = 4
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 = Weekday(.Value2, vbMonday) > 5 '<--| set its corresponding Row 'Hidden' property to True if currently referenced cell has wanted color
End With
Next
End If
Application.ScreenUpdating = True
End Sub
For rowCnt = endRow To beginRow step -1
instead ofFor rowCnt = beginRow To endRow
if your code doesn't hide the right rows. – Pspl