
Sub calcola()
Dim UR As Long, X As Long, DD1 As Long, DD2 As Long
Dim Tot As Date, Tot1 As Date, Tot2 As Double
Dim Inizio1 As Date, Fine1 As Date, Inizio As Date, Fine As Date
Inizio1 = #6:00:00 AM# 'orario inizio normale
Fine1 = #10:00:00 PM# 'orario fine normale
UR = Range("A" & Rows.Count).End(xlUp).Row
For X = 2 To UR
DD1 = Day(Cells(X, 4))
DD2 = Day(Cells(X, 5))
Inizio = Format(Cells(X, 4), "hh:mm:ss")
Fine = Format(Cells(X, 5), "hh:mm:ss")
Tot = 0
If Fine <= Fine1 And Inizio <= Fine1 And Inizio >= Inizio1 Then
If DD2 = DD1 Then
Tot = Format(Fine - Inizio, "hh:mm:ss")
' Tot1 = Tot1 + Tot
Else
Tot = Format(Fine1 - Inizio, "hh:mm:ss")
' Tot2 = Tot2 + Tot
End If
End If
Cells(X, 9) = Tot
Next X
End Sub
|
M2 =ASS((RESTO(J2-I2;1)*24-(J2 |
Sub calcola2()
Dim UR As Long, X As Long, DD1 As Long, DD2 As Long
Dim Tot As Date, Tot1 As Date, Tot2 As Double
Dim Inizio1 As Date, Fine1 As Date, Inizio As Date, Fine As Date, mezzanotte As Date, ore2 As Date
Inizio1 = #6:00:00 AM# 'orario inizio normale
Fine1 = #10:00:00 PM# 'orario fine normale
ore2 = #2:00:00 AM#
UR = Range("A" & Rows.Count).End(xlUp).Row
For X = 2 To UR
DD1 = Day(Cells(X, 4))
DD2 = Day(Cells(X, 5))
Inizio = Format(Cells(X, 4), "hh:mm:ss")
Fine = Format(Cells(X, 5), "hh:mm:ss")
Tot = 0
If Fine <= Fine1 And Inizio <= Fine1 And Inizio >= Inizio1 Then
If DD2 = DD1 Then
Tot = Format(Fine - Inizio, "hh:mm:ss")
Else
Tot = Format(Fine1 - Inizio, "hh:mm:ss")
End If
Cells(X, 14) = Format(Tot, "hh:mm:ss")
End If
If Fine <= Inizio1 Then ' And Inizio >= Fine1 Then
If DD2 = DD1 Then
Tot = Format(Fine - Inizio, "hh:mm:ss")
Else
If Inizio < Fine1 Then Inizio = Fine1
Tot = Format(ore2 + Fine - Inizio + Fine1, "hh:mm:ss")
End If
Cells(X, 15) = Format(Tot, "hh:mm:ss")
End If
Next X
End Sub
|
"=ASS((RESTO(J2-I2;1)*24-(J2 |
