Sub statistics()
'Column W(Description) And X(counts)
'Rows 1 - 3
'Business weekday 00:00 - 07:00 i 20:00 do 24:00 Count1
'Sat/Sun Count2
'not important Count3
Dim DateofEntry As String
Dim TimeofEntry As String
Dim conventry As String
Dim count1 As Integer
Dim count2 As Integer
Dim count3 As Integer
Dim WS As Worksheet
' Zero counts
count1 = 0
count2 = 0
count3 = 0
On Error GoTo errhandle
For Each WS In Worksheets
count1 = 0
count2 = 0
count3 = 0
For Each cell In WS.Range("E2", Range("E65536").End(xlUp).Address)
'Note: format of cell YYYY-MM-DD HH:MM:SS
If cell.Value <> "" And Len(cell.Value) > 0 Then
conventry = Format(cell.Value, "yyyy-mm-dd hh:mm:ss")
DateofEntry = Left(conventry, 19)
TimeofEntry = Replace((Right(conventry, 9)), ":", "")
If Weekday(DateofEntry, vbMonday) < 6 And TimeofEntry >= 0 And TimeofEntry <= 70000 Then count1 = count1 + 1
Else: count3 = count2 + count1
End If
Next cell
For Each cell In WS.Range("E2", Range("E65536").End(xlUp).Address)
'Note: format of cell YYYY-MM-DD HH:MM:SS
If cell.Value <> "" And Len(cell.Value) > 0 Then
conventry = Format(cell.Value, "yyyy-mm-dd hh:mm:ss")
DateofEntry = Left(conventry, 19)
TimeofEntry = Replace((Right(conventry, 9)), ":", "")
If Weekday(DateofEntry, vbMonday) < 6 And TimeofEntry >= 200000 And TimeofEntry <= 239999 Then count1 = count1 + 1
Else: count3 = count2 + count1
End If
Next cell
For Each cell In WS.Range("E2", Range("E65536").End(xlUp).Address)
'Note: format of cell YYYY-MM-DD HH:MM:SS
If cell.Value <> "" And Len(cell.Value) > 0 Then
conventry = Format(cell.Value, "yyyy-mm-dd hh:mm:ss")
DateofEntry = Left(conventry, 19)
TimeofEntry = Replace((Right(conventry, 9)), ":", "")
If Weekday(DateofEntry, vbMonday) >= 6 Then count2 = count2 + 1
Else: count3 = count2 + count1
End If
Next cell
With WS
.Range("W3").Value = "Business weekday"
.Range("W4").Value = "Sat & Sun"
.Range("X2").Value = "il"
.Range("X3").Value = count1 'Business weekday
.Range("X4").Value = count2 'Sat & Sun
End With
Next WS
Exit Sub
errhandle:
If Err.Number = 13 Then
MsgBox " Sprawdż format komórek: RRRR-MM-DD HH:MM:SS"
Err.Clear
End If
End Sub
Bookmarks