16 For Next VBA Excel
Sub GestionRRHH_Cumpleaños() Dim i As Integer Dim mesActual As Integer Dim antiguedad As Integer Dim fechaNac As Date Dim fechaIng As Date ' Obtenemos el mes actual del sistema (5 para Mayo) mesActual = Month(Date) ' Recorremos de la fila 2 a la 7 (ajusta el 7 según tu lista) For i = 2 To 7 fechaNac = Cells(i, 2).Value fechaIng = Cells(i, 3).Value ' 1. Verificamos Cumpleaños If Month(fechaNac) = mesActual Then Cells(i, 4).Value = "¡FELICITAR POR SU CUMPLEAÑOS! " Cells(i, 4).Font.Bold = True Cells(i, 4).Interior.Color = vbGreen Else Cells(i, 4).Value = "" Cells(i, 4).Interior.Color = xlNone End If ' 2. EXTRA: Cálculo de Antigüedad ' DateDiff "yyyy" calcula la diferencia en años antiguedad = DateDiff("yyyy", fechaIng, Date) ' Concatenamos la antigüedad al mensaje existente Cells(i, 4).Value = Cells(i, 4).Value & vbCrLf & "(" & antiguedad & " años en la empresa)" Next i MsgBox "Reporte de RRHH actualizado correctamente.", vbInformation End Sub
Download
0 formatsNo download links available.