
Sub prova()
Dim ur As Integer, rng As Range, rng3 As Range, rng4 As Range, rng5 As Range, rng19 As Range, cella As Range, data As String
With Sheets("foglio1")
ur = .Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Range(.Cells(2, 1), .Cells(ur, 1))
Set rng3 = Range(.Cells(2, 3), .Cells(ur, 3))
Set rng4 = Range(.Cells(2, 4), .Cells(ur, 4))
Set rng5 = Range(.Cells(2, 5), .Cells(ur, 5))
Set rng19 = Range(.Cells(2, 19), .Cells(ur, 19))
End With
For Each cella In rng3
If cella <> 0 Then
cella = (Right(cella, 2) & "/" & Mid(cella, 5, 2) & "/" & Left(cella, 4))
End If
Next
For Each cella In rng4
If cella <> 0 Then
cella = (Right(cella, 2) & "/" & Mid(cella, 5, 2) & "/" & Left(cella, 4))
End If
Next
For Each cella In rng5
If cella <> 0 Then
cella = (Right(cella, 2) & "/" & Mid(cella, 5, 2) & "/" & Left(cella, 4))
End If
If cella = 0 Then
cella = Date
End If
Next
For Each cella In rng19
If cella <> 0 Then
cella = (Right(cella, 2) & "/" & Mid(cella, 5, 2) & "/" & Left(cella, 4))
End If
Next
For Each cella In rng
cella.Offset(0, 5) = DateDiff("d", cella.Offset(0, 3), cella.Offset(0, 4))
Next
Cells(2, 1) = Application.WorksheetFunction.Average(Range("f:f"))
'RIPRISTIONO FORMATO INIZIALE
For Each cella In rng3
cella = (Right(cella(1, 1), 4) & Mid(cella(1, 1), 4, 2) & Left(cella(1, 1), 2))
cella.NumberFormat = "General"
Next
For Each cella In rng4
cella = (Right(cella(1, 1), 4) & Mid(cella(1, 1), 4, 2) & Left(cella(1, 1), 2))
cella.NumberFormat = "General"
Next
For Each cella In rng5
If cella = Date Then
cella = "0"
cella.NumberFormat = "General"
End If
If cella <> 0 Then
cella = (Right(cella(1, 1), 4) & Mid(cella(1, 1), 4, 2) & Left(cella(1, 1), 2))
cella.NumberFormat = "General"
End If
Next
For Each cella In rng19
cella = (Right(cella(1, 1), 4) & Mid(cella(1, 1), 4, 2) & Left(cella(1, 1), 2))
cella.NumberFormat = "General"
Next
End Sub |
Option Explicit
Sub prova_2()
Dim ur As Integer, rng As Range, cella As Range
Dim date_from As Date, date_to As Date
ur = Sheets("foglio1").Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Range("D2:D" & ur)
'scandisce colonna D
For Each cella In rng
'se in colonna D c'è zero, imposta la data odierna
If cella = 0 Then
date_from = Date
Else
date_from = CDate(Right(cella, 2) & "/" & Mid(cella, 5, 2) & "/" & Left(cella, 4))
End If
'se in colonna E c'è zero, imposta la data odierna
If cella.Offset(, 1) = 0 Then
date_to = Date
Else
date_to = CDate(Right(cella.Offset(, 1), 2) & "/" & Mid(cella.Offset(, 1), 5, 2) & "/" & Left(cella.Offset(, 1), 4))
End If
'calcola la difefrenza in giorni tra le due date
cella.Offset(, 2) = DateDiff("d", date_from, date_to)
Next
[A2] = [AVERAGE(F:F)]
MsgBox "Fatto."
End Sub |
=SE(C2<=D2;DATA(SINISTRA(D2;4);STRINGA.ESTRAI(D2;5;2);DESTRA(D2;2))-DATA(SINISTRA(C2;4);STRINGA.ESTRAI(C2;5;2);DESTRA(C2;2))+1;DATA(SINISTRA(C2;4);STRINGA.ESTRAI(C2;5;2);DESTRA(C2;2))-DATA(SINISTRA(D2;4);STRINGA.ESTRAI(D2;5;2);DESTRA(D2;2))+1) |
For Each cella In rng
'se in colonna D c'è zero, imposta la data odierna
If cella = 0 And cella.Offset(, 5) = x Then
date_from = Date
Else |
Sub prova2()
Dim i
Dim Data_I As Date, Data_F As Date
On Error Resume Next
Application.EnableEvents = False
For i = 2 To Cells(Rows.Count, "D").End(xlUp).Row
If Cells(i, "F") = "" Then
Data_I = CDate(Left(Cells(i, "D"), 4) & "/" & Mid(Cells(i, "D"), 5, 2) & "/" & Right(Cells(i, "D"), 2))
If Cells(i, "E") = 0 Then
Data_F = Date
Else
Data_F = CDate(Left(Cells(i, "E"), 4) & "/" & Mid(Cells(i, "E"), 5, 2) & "/" & Right(Cells(i, "E"), 2))
End If
End If
Cells(i, "F") = Data_F - Data_I ''+ 1 normalmente si usa
Next i
Application.EnableEvents = True
End Sub |
For Each cella In rng
'se in colonna D c'è zero e si riferisce a Mario, imposta la data odierna
If cella = 0 And cella.Offset(, 3) = "MARIO" Then
date_from = Date
ElseIf cella = 0 Then 'se in colonna D c'è zero imposta comunque la data odierna
date_from = Date
Else
date_from = CDate(Right(cella, 2) & "/" & Mid(cella, 5, 2) & "/" & Left(cella, 4))
End If
....
... |
If Trim(x) = Trim(cella) And Trim(cella.Offset(0, -4).Value) = "0" And Trim(cella.Offset(0, -2).Value) = "vecchio frac" Then
APERTE = APERTE + 1
cella.Offset(0, -4).Value = Format(Date, "yyyymmdd")
End If
If Trim(x) = Trim(cella) And Trim(cella.Offset(0, -4).Value) <> "0" And Trim(cella.Offset(0, -2).Value) = "vecchio frac" Then
cella.Offset(0, 17) = Trim(cella.Offset(0, -4).Value) - Trim(cella.Offset(0, -5).Value)
max = Application.WorksheetFunction.max(T)
min = Application.WorksheetFunction.min(T)
End If
If Trim(x) = Trim(cella) And Trim(cella.Offset(0, -4).Value) = Format(Date, "yyyymmdd") And Trim(cella.Offset(0, -2).Value) = "D9" Then
cella.Offset(0, -4).Value = "0"
End If
|
Option Explicit
Sub minmaxmedia()
Dim ur As Integer, rng As Range, cella As Range
Dim date_from As Date, date_to As Date
ur = Sheets("foglio1").Cells(Rows.Count, "C").End(xlUp).Row
Set rng = Range("D2:D" & ur)
'scandisce colonna D
For Each cella In rng
'se in colonna D c'è zero, imposta la data odierna
If cella = 0 And LCase(cella.Offset(, 3)) = "mario" Then
date_from = Date
ElseIf cella = 0 Then 'se in colonna D c'è zero imposta comunque la data odierna
date_from = Date
Else
date_from = CDate(Right(cella, 2) & "/" & Mid(cella, 5, 2) & "/" & Left(cella, 4))
End If
'se in colonna E c'è zero, imposta la data odierna
If cella.Offset(, 1) = 0 And LCase(cella.Offset(, 3)) = "mario" Then
date_from = Date
ElseIf cella.Offset(, 1) = 0 Then 'se in colonna E c'è zero imposta comunque la data odierna
date_from = Date
Else
date_from = CDate(Right(cella.Offset(, 1), 2) & "/" & Mid(cella.Offset(, 1), 5, 2) & "/" & Left(cella.Offset(, 1), 4))
End If
'calcola la differenza in giorni tra le due date
cella.Offset(, 21) = DateDiff("d", date_from, date_to)
Next
[A2] = [AVERAGE(y:y)]
[A3] = [MAX(y:y)]
[A4] = [MIN(y:y)]
MsgBox "Fatto."
End Sub
|
