voitoosh,
Attached is an example workbook based on the criteria you described.
Cell B1 contains a drop-down list where you can pick the month
Cell B2 contains a drop-down list where you can pick the year
The sheet containing those lists is on sheet 'Lists' and they are named ranges listMonths and listYears.
Cell B3 uses a formula to calculate the number of days for the selected Month and Year:
=IF(COUNTBLANK(B1:B2)>0,"",DAY(EOMONTH(DATE(B2,MATCH(B1,listMonths,0),1),0)))
Then in row 5 are headers.
Column A contains names and Column B contains their employee ID's (these are made up in my example)
In cell C5 and copied right is this formula to show the day number (and it will only go to the number of days for the selected month):
=IF(OR(COLUMNS($C5:C5)>$B$3,$B$3=""),"","Day "&COLUMNS($C5:C5))
In cell AI6 and copied down is this formula to get the number of consecutive blanks greater than 5:
=IF($B$3="","",CountConsecutiveBlanks(C6:INDEX(C6:AG6,0,$B$3),5,TRUE))
In cell AI7 and copied down is this formula to get the number of cells for each block of consecutive blanks greater than 5:
=IF($B$3="","",CountConsecutiveBlanks(C6:INDEX(C6:AG6,0,$B$3),5,FALSE))
Those formulas utilize a UDF (User Defined Function) that I created named CountConsecutiveBlanks which is defined with this code:
Public Function CountConsecutiveBlanks(ByVal rRange As Range, _
ByVal lThreshold As Long, _
Optional ByVal bCountOverThreshold As Boolean = True) As Variant
'This function can be used in two ways
'By default it counts the number of times that consecutive blank cells are greater than the Threshold
'If bCountOverThreshold is set to FALSE, this function will return the individual cell counts for blank cells _
where the consecutive blank cell streak is greater than the threshold
Dim rCell As Range
Dim lBlankCounter As Long
Dim lBlanksOverThreshold As Long
Dim sBlankCount As String
For Each rCell In rRange.Cells
If IsEmpty(rCell) Then
lBlankCounter = lBlankCounter + 1
Else
If lBlankCounter > lThreshold Then
lBlanksOverThreshold = lBlanksOverThreshold + 1
sBlankCount = sBlankCount & ", " & lBlankCounter
End If
lBlankCounter = 0
End If
Next rCell
If lBlankCounter > lThreshold Then
lBlanksOverThreshold = lBlanksOverThreshold + 1
sBlankCount = sBlankCount & ", " & lBlankCounter
End If
Select Case bCountOverThreshold
Case True: CountConsecutiveBlanks = lBlanksOverThreshold
Case Else: CountConsecutiveBlanks = Mid(sBlankCount, 3)
End Select
End Function
The formula accepts three arguments:
rRange: This is the range of cells that the formula will check for blanks
lThreshold: This is the threshold of consecutive blanks that must be exceeded in order to be counted. Because you need this to count greater than 5, I have set it to 5 in the formulas shown above.
[bCountOverThreshold]: This is an optional boolean (true/false) value. By default it is set to true. When true, it will count the number of blocks of consecutive blanks that are greater than the threshold. When false, it will give a count of the number of cells for each block of consecutive blanks greater than the threshold.
Note that I have used the Freeze Panes feature to keep the Month/Year and Names visible, as well as the Day #'s, so that you can scroll right and down and still be aware of which employee for what day you're looking at. You will also have to enable macros for the UDF to work properly, otherwise it will display a #NAME? error.
Does that work for you?
Bookmarks