Ciao oregon sei un grande !!! Bravissimo !!!! Funziona !!!!!![]()
Posto tutto il codice x chi fosse interessato ....
Se per caso ci fosse in qualche punto, qualche ridondanza di codice, la segnalazione fa sempre piacere per scrivere in futuro un codice sempre più corretto...
Grazie ancora !!
codice:Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) On Error GoTo errore Dim CNom As Variant, CNasc As Variant, CEta As Variant, CAss As Variant, CEsp As Variant Dim e As Integer, e2 As Integer, r As Long, r2 As Long Dim dFr, dFr2, dTo ' CNom = Application.Match("Nominativo", Sheets("Persone").Rows(1), 0) CNasc = Application.Match("Data di nascita (gg/mm/aaaa)", Sheets("Persone").Rows(1), 0) CEta = Application.Match("Età", Sheets("Persone").Rows(1), 0) CAss = Application.Match("Data assunz. (gg/mm/aaaa)", Sheets("Persone").Rows(1), 0) CEsp = Application.Match("Esperienza", Sheets("Persone").Rows(1), 0) If Cells(Target.Row, CNom) <> "" And Cells(Target.Row, CNasc) <> "" Then r = Target.Row Application.EnableEvents = False If r > 1 Then dFr = Cells(r, CNasc) dTo = DateSerial(Year(Now()), 12, 31) e = DateDiff("yyyy", dFr, dTo) Cells(r, CEta).Value = e If e >= 18 And e <= 67 Then Cells(r, CEta).Interior.ColorIndex = xlNone Else With Cells(r, CEta).Interior .Color = 16751103 .TintAndShade = 0 End With End If End If Application.EnableEvents = True End If If Cells(Target.Row, CNom) <> "" And Cells(Target.Row, CAss) <> "" Then r2 = Target.Row Application.EnableEvents = False If r2 > 1 Then dFr2 = Cells(r, CAss) dTo = DateSerial(Year(Now()), 12, 31) e2 = DateDiff("yyyy", dFr2, dTo) Cells(r2, CEsp).Value = e2 Application.EnableEvents = True End If End If xit: Application.EnableEvents = True Exit Sub errore: MsgBox Err.Number & " - " & Err.Description Resume xit End Sub

Rispondi quotando