Moderatori: Anthony47, Flash30005
=SE(DATA.DIFF(C6;OGGI();"y")>0;DATA.DIFF(C6;OGGI();"y") & " Anni ";"") & SE(DATA.DIFF(C6;OGGI();"ym")>0;DATA.DIFF(C6;OGGI();"ym") & " Mesi ";"") & DATA.DIFF(C6;OGGI();"md") & " Giorni"
Public Function Eta(Nascita As Date, Optional DataCorrente As Variant) As String
'Se non metti la data corrente prende in automatico la data odierna
If IsMissing(DataCorrente) Then DataCorrente = Date
Dim Anni As Integer
Dim Mesi As Integer
Dim Giorni As Integer
'Calcolo gli anni
Anni = Year(DataCorrente) - Year(Nascita)
If DateSerial(Year(DataCorrente), Month(Nascita), Day(Nascita)) > DataCorrente Then
Anni = Anni - 1
End If
'Calcolo i mesi
If Month(Nascita) = Month(DataCorrente) Then
If Day(Nascita) < Day(DataCorrente) Then
Mesi = 0
End If
If Day(Nascita) > Day(DataCorrente) Then
Mesi = 11
End If
End If
If Month(Nascita) > Month(DataCorrente) Then
Mesi = 12 - Month(Nascita) + Month(DataCorrente)
If Day(Nascita) > Day(DataCorrente) Then
Mesi = Mesi - 1
End If
End If
If Month(Nascita) < Month(DataCorrente) Then
Mesi = Month(DataCorrente) - Month(Nascita)
If Day(Nascita) > Day(DataCorrente) Then
Mesi = Mesi - 1
End If
End If
'Calcolo i giorni
If Month(Nascita) < Month(DataCorrente) Then
If Day(Nascita) > Day(DataCorrente) Then
Giorni = Day(DateSerial(Year(DataCorrente), Month(Nascita) + 1, 0)) - Day(Nascita) + Day(DataCorrente)
End If
If Day(Nascita) < Day(DataCorrente) Then
Giorni = Day(DataCorrente) - Day(Nascita)
End If
End If
If Month(Nascita) = Month(DataCorrente) Then
If Day(Nascita) > Day(DataCorrente) Then
Giorni = Day(DateSerial(Year(DataCorrente), Month(Nascita), 0)) - Day(Nascita) + Day(DataCorrente)
End If
If Day(Nascita) < Day(DataCorrente) Then
Giorni = Day(DataCorrente) - Day(Nascita)
End If
End If
If Month(Nascita) > Month(DataCorrente) Then
If Day(Nascita) > Day(DataCorrente) Then
Giorni = Day(DateSerial(Year(DataCorrente), Month(Nascita) + 1, 0)) - Day(Nascita) + Day(DataCorrente)
End If
If Day(Nascita) < Day(DataCorrente) Then
Giorni = Day(DataCorrente) - Day(Nascita)
End If
End If
Eta = Anni & IIf(Anni <= 1, " anno ", " anni ") & Mesi & IIf(Mesi <= 1, " mese ", " mesi ") & Giorni & IIf(Giorni <= 1, " giorno", " giorni")
End Function
=SE(C6>0;ANNULLA.SPAZI(SE(OGGI()-C6;TESTO(DATA.DIFF(C6;OGGI();"y");"[>1]0"" anni"";[>]""1 anno"";")&TESTO(DATA.DIFF(C6;OGGI();"ym");"[>1] 0 "" mesi "";[>]"" 1 mese""; ")&TESTO(DATA.DIFF(C6;OGGI();"md");"[>1] 0 "" giorni"";[>]"" 1 giorno"";");" 0 giorno"));"")
Function Eta2(ByVal DInit As Date, Optional dEnd As Date = 0) As String
Dim dY As Long, cYY As Long, cMM As Long, cDD As Long, myOut As String
'
DInit = Int(DInit)
If dEnd = 0 Then dEnd = Date
If Year(DInit) < 1901 Then
dY = 1901 - Year(DInit)
DInit = DateSerial(1901, Month(DInit), Day(DInit))
End If
'
cYY = Evaluate("=DATEDIF(" & CLng(DInit) & "," & CLng(dEnd) & ", ""Y"")")
cMM = Evaluate("=DATEDIF(" & CLng(DInit) & "," & CLng(dEnd) & ", ""YM"")")
cDD = Evaluate("=DATEDIF(" & CLng(DInit) & "," & CLng(dEnd) & ", ""MD"")")
'
If (cYY + dY) > 1 Then myOut = cYY + dY & " Anni "
If (cYY + dY) = 1 Then myOut = cYY + dY & " Anno "
If cMM > 1 Then myOut = myOut & cMM & " Mesi "
If cMM = 1 Then myOut = myOut & cMM & " Mese "
'If Len(myOut) = 0 Then
If cDD > 1 Or cDD = 0 Then myOut = myOut & cDD & " Giorni "
If cDD = 1 Then myOut = myOut & cDD & " Giorno "
'End If
Eta2 = myOut
End Function
Function Eta3(ByVal DIn As String, Optional dOut As String = "") As Variant
'vedi http://www.pc-facile.com/forum/viewtopic.php?f=26&t=109035
'
Dim dY As Long, cYY As Long, cMM As Long, cDD As Long, myOut As String
Dim dE As Long, DInit As Date, DEnd As Date
'
DInit = DateSerial(Year(DIn), Month(DIn), Day(DIn))
DEnd = DateSerial(Year(dOut), Month(dOut), Day(dOut))
If DEnd < DInit Then Eta3 = CVErr(xlErrNA): Exit Function
If Month(DateSerial(Year(DIn), 2, 29)) = 2 Then myc = 1904 Else myc = 1903
If DEnd = 0 Then DEnd = Date
If Year(DInit) < myc Then
dY = myc - Year(DInit)
DInit = DateSerial(myc, Month(DInit), Day(DInit))
End If
If Month(DateSerial(Year(DEnd), 2, 29)) = 2 Then myc = 1908 Else myc = 1907
If Year(DEnd) < myc Then
dE = myc - Year(DEnd)
DEnd = DateSerial(myc, Month(DEnd), Day(DEnd))
End If
'
cYY = Evaluate("=DATEDIF(" & CLng(DInit) & "," & CLng(DEnd) & ", ""Y"")")
cMM = Evaluate("=DATEDIF(" & CLng(DInit) & "," & CLng(DEnd) & ", ""YM"")")
cDD = Evaluate("=DATEDIF(" & CLng(DInit) & "," & CLng(DEnd) & ", ""MD"")")
'
If (cYY + dY - dE) > 1 Then myOut = cYY + dY - dE & " Anni "
If (cYY + dY - dE) = 1 Then myOut = cYY + dY - dE & " Anno "
If cMM > 1 Then myOut = myOut & cMM & " Mesi "
If cMM = 1 Then myOut = myOut & cMM & " Mese "
'If Len(myOut) = 0 Then
If cDD > 1 Or (cDD = 0 And Len(myOut) = 0) Then myOut = myOut & cDD & " Giorni "
If cDD = 1 Then myOut = myOut & cDD & " Giorno "
'End If
Eta3 = myOut
End Function
Function Eta3(ByVal DIn As String, Optional dOut As String = "") As Variant
'vedi http://www.pc-facile.com/forum/viewtopic.php?f=26&t=109035
'
Dim dY As Long, cYY As Long, cMM As Long, cDD As Long, myOut As String
Dim dE As Long, DInit As Date, DEnd As Date
'
If dOut = "" Then dOut = Format(Date, "dd/mm/yyyy") 'AGGIUNGERE!!!
DInit = DateSerial(Year(DIn), Month(DIn), Day(DIn))
'etc etc
=SE(B3<>"";Eta3(B3;D3);"")
Private Sub Workbook_Open()
Application.CalculateFull
End Sub
Torna a Applicazioni Office Windows
Supporto per sviluppo macro VBA Ordinare per data Autore: Carletto Ribolla |
Forum: Applicazioni Office Windows Risposte: 3 |
Eliminare righe diverse dalla prima data del mese Autore: dipdip |
Forum: Applicazioni Office Windows Risposte: 4 |
Come impostare il formato data predefinito in excel? Autore: wallace&gromit |
Forum: Applicazioni Office Windows Risposte: 5 |
Macro sposta riga se data in colonna più vecchia di 3 mesi Autore: systemcrack |
Forum: Applicazioni Office Windows Risposte: 23 |
Visitano il forum: Nessuno e 16 ospiti