You are on page 1of 7

Private Sub CmdEjecutar_Click()

Range("a2").Activate
'Cuenta = Me.LstHisNom.ListCount
Set rango = Range("A1").CurrentRegion

CargarEmpleado Cells(2, 1), Cells(2, 4)

Set a = Sheets("Bonos2022")
a.Cells.Clear
filaedit = 1
For x = 0 To Me.LstBonEmp.ListCount - 1
a.Cells(filaedit, "A") = Me.LstBonEmp.List(x, 0)
a.Cells(filaedit, "B") = Me.LstBonEmp.List(x, 1)
a.Cells(filaedit, "C") = Me.LstBonEmp.List(x, 2)
a.Cells(filaedit, "D") = Me.LstBonEmp.List(x, 3)
a.Cells(filaedit, "D") = Me.LstBonEmp.List(x, 4)
a.Cells(filaedit, "E") = Me.LstBonEmp.List(x, 5)
a.Cells(filaedit, "f") = Me.LstBonEmp.List(x, 6)
a.Cells(filaedit, "G") = Me.LstBonEmp.List(x, 7)
a.Cells(filaedit, "H") = Me.LstBonEmp.List(x, 8)
a.Cells(filaedit, "I") = Me.LstBonEmp.List(x, 9)
a.Cells(filaedit, "J") = Me.LstBonEmp.List(x, 10)
a.Cells(filaedit, "K") = Me.LstBonEmp.List(x, 11)
a.Cells(filaedit, "L") = Me.LstBonEmp.List(x, 12)
a.Cells(filaedit, "M") = Me.LstBonEmp.List(x, 13)
a.Cells(filaedit, "N") = Me.LstBonEmp.List(x, 14)
a.Cells(filaedit, "O") = Me.LstBonEmp.List(x, 15)
a.Cells(filaedit, "P") = Me.LstBonEmp.List(x, 16)
'a.Cells(filaedit, �Q�) = Me.LstBonEmp.List(x, 17)

filaedit = filaedit + 1
Next x

'For i = 0 To Cuenta - 1
' If Me.LstHisNom.Selected(i) Then
' valor = Me.LstHisNom.List(i, 1)
' rango.Find(What:=valor, LookAt:=xlWhole, After:=ActiveCell).Activate
'Cargar el listBox Bonificaci�n
' x = Val(Me.LstHisNom.List(i, 0))
' CargarEmpleado Cells(x, 1), Cells(x, 3)
'
' End If
'Next i
End Sub

Private Sub UserForm_Activate()


'cargar las columnas para la maestra empleado

With Me.LstMasEmp
.ColumnCount = 34
End With

EncabezdoBonEmp
EncabezdoHisNom

With Me
' Limpiar el TextBox, combobox y agregar las columnas de busqueda
' .TxtValor.Value = ""
' .CbxCampos.Clear
.LstMasEmp.Visible = True
.LstBonEmp.Visible = True
.LstMasEmp.ColumnWidths = "80 pt;80 pt;80 pt;80 pt"
.LstBonEmp.ColumnWidths = "90 pt;90 pt;90 pt;90 pt"
.LstHisNom.ColumnWidths = "80 pt;80 pt;80 pt;80 pt"
'.CbxCampos.List =
Application.Transpose(ActiveCell.CurrentRegion.Resize(1).Value)
'.CbxCampos.ListStyle = fmListStyleOption
End With

'Llenar la lista de la maestra de empleados


Me.LstMasEmp.Clear
Me.LstMasEmp.RowSource = "listado_de_empleados"

End Sub

Private Sub EncabezdoBonEmp()


'Cargar las columnas para la Bonificaci�n
With Me.LstBonEmp
.ColumnCount = 17
.List = Range(Cells(1, 1), Cells(1, .ColumnCount)).Value
.RemoveItem 0
End With

i = Me.LstBonEmp.ListCount
Me.LstBonEmp.AddItem
Me.LstBonEmp.List(i, 0) = "Linea"
Me.LstBonEmp.List(i, 1) = "EmpID"
Me.LstBonEmp.List(i, 2) = "Empleado"
Me.LstBonEmp.List(i, 3) = "C�dula"
Me.LstBonEmp.List(i, 4) = "Depto."
Me.LstBonEmp.List(i, 5) = "Fec. Ingreso"
Me.LstBonEmp.List(i, 6) = "Fec. Salida"
Me.LstBonEmp.List(i, 7) = "Ene"
Me.LstBonEmp.List(i, 8) = "Feb"
Me.LstBonEmp.List(i, 9) = "Mar"
Me.LstBonEmp.List(i, 10) = "Abr"
Me.LstBonEmp.List(i, 11) = "May"
Me.LstBonEmp.List(i, 12) = "Jun"
Me.LstBonEmp.List(i, 13) = "Jul"
Me.LstBonEmp.List(i, 14) = "Ago"
Me.LstBonEmp.List(i, 15) = "Sep"
Me.LstBonEmp.List(i, 16) = "Total Acumulado"

End Sub

Private Sub EncabezdoHisNom()


'Cargar las columnas para el hist�rico de N�mina
Dim rango As Range

With Me.LstHisNom
.ColumnCount = 22
.List = Range(Cells(1, 1), Cells(1, .ColumnCount)).Value
.RemoveItem 0
End With
Me.LstHisNom.RowSource = "TbNomina"

On Error GoTo 0

End Sub

Private Sub CargarEmpleado(EmpID As String, Mes As String)


Dim TotalEne, TotalFeb, TotalMar, TotalAbr, TotalMay, TotalJun, TotalJul, TotalAgo,
TotalSep, TotalAcu As Currency
Dim ActEmpID As String
Dim ActMes As Integer

' Guarda el empleado de inicio y actual mes en proceso

ActEmpID = Val(EmpID)
ActMes = Val(Mes)

'Presentar mensajes para verificaci�n del c�digo


'MsgBox "El empleado inicial es: " & ActEmpID & " en el mes " & ActMes
'MsgBox "El empleado inicial listado es: " & Me.LstHisNom.List(0, 0) & " en el mes
" & Me.LstHisNom.List(0, 3)
'MsgBox "El primer moviemiento es: " & Me.LstHisNom.List(0, 13)

'Inicializa las variables para los totales


TotalEne = 0
TotalFeb = 0
TotalMar = 0
TotalAbr = 0
TotalMay = 0
TotalJun = 0
TotalJul = 0
TotalAgo = 0
TotalSep = 0
TotalAcu = 0

'Limpiar los listbox de los Bonos


Me.LstBonEmp.Clear

'Poner nuevamente los encabezdos para el ListBox de los Bonos

EncabezdoBonEmp

'Busca por la Columna del Mes que es la 3


columna = 3
i = 1 'Para ir contando los empleados
d = 1
For x = 0 To Me.LstHisNom.ListCount - 1
'Validar que sea el mismo empleado
If Val(Me.LstHisNom.List(x, 0)) = 5880 Then MsgBox "el Movimieno es: " &
Me.LstHisNom.List(x, 13) & " Por: " & Me.LstHisNom.List(x, 7)
SW = Val(Me.LstHisNom.List(x, 0))
If SW = Val(ActEmpID) Then
'Validar que el movimiento sea: Sueldo, Incentivo O Producido
If (Trim(LCase(Me.LstHisNom.List(x, 13))) = LCase("Sueldo")) Then
'Validar que el Monto sea positivo
If Val(Me.LstHisNom.List(x, 7)) > 0 Then
'acumular el monto al mes correspondiente
If ActMes = 1 Then TotalEne = TotalEne + Val(Me.LstHisNom.List(x, 7))
If ActMes = 2 Then TotalFeb = TotalFeb + Val(Me.LstHisNom.List(x, 7))
If ActMes = 3 Then TotalMar = TotalMar + Val(Me.LstHisNom.List(x, 7))
If ActMes = 4 Then TotalAbr = TotalAbr + Val(Me.LstHisNom.List(x, 7))
If ActMes = 5 Then TotalMay = TotalMay + Val(Me.LstHisNom.List(x, 7))
If ActMes = 6 Then TotalJun = TotalJun + Val(Me.LstHisNom.List(x, 7))
If ActMes = 7 Then TotalJul = TotalJul + Val(Me.LstHisNom.List(x, 7))
If ActMes = 8 Then TotalAgo = TotalAgo + Val(Me.LstHisNom.List(x, 7))
If ActMes = 9 Then TotalSep = TotalSep + Val(Me.LstHisNom.List(x, 7))

' Acumular valor de los meses


TotalAcu = TotalAcu + Val(Me.LstHisNom.List(x, 7))

'Actualiza el Mes en proceso


ActMes = Val(Me.LstHisNom.List(x, 3))
End If 'valido que el valor sea positvo (valor > 0)
End If 'valido movimiento del tipo: Sueldo, Icentivo , Producido

If Val(Me.LstHisNom.List(x, 0)) = 5880 Then MsgBox "el Movimieno es: " &
Me.LstHisNom.List(x, 13) & " Por: " & Me.LstHisNom.List(x, 7)

If (Trim(LCase(Me.LstHisNom.List(x, 13))) = LCase("Incentivo")) Then


'Validar que el Monto sea positivo
If Val(Me.LstHisNom.List(x, 7)) > 0 Then

'acumular el monto al mes correspondiente


If ActMes = 1 Then TotalEne = TotalEne + Val(Me.LstHisNom.List(x, 7))
If ActMes = 2 Then TotalFeb = TotalFeb + Val(Me.LstHisNom.List(x, 7))
If ActMes = 3 Then TotalMar = TotalMar + Val(Me.LstHisNom.List(x, 7))
If ActMes = 4 Then TotalAbr = TotalAbr + Val(Me.LstHisNom.List(x, 7))
If ActMes = 5 Then TotalMay = TotalMay + Val(Me.LstHisNom.List(x, 7))
If ActMes = 6 Then TotalJun = TotalJun + Val(Me.LstHisNom.List(x, 7))
If ActMes = 7 Then TotalJul = TotalJul + Val(Me.LstHisNom.List(x, 7))
If ActMes = 8 Then TotalAgo = TotalAgo + Val(Me.LstHisNom.List(x, 7))
If ActMes = 9 Then TotalSep = TotalSep + Val(Me.LstHisNom.List(x, 7))

' Acumular valor de los meses


TotalAcu = TotalAcu + Val(Me.LstHisNom.List(x, 7))

'Actualiza el Mes en proceso


ActMes = Val(Me.LstHisNom.List(x, 3))
End If 'valido que el valor sea positvo (valor > 0)
End If 'valido movimiento Icentivo

If (Trim(LCase(Me.LstHisNom.List(x, 13))) = LCase("Producido")) Then


If Val(Me.LstHisNom.List(x, 0)) = 5880 Then MsgBox "el Movimieno es: " &
Me.LstHisNom.List(x, 13) & " Por: " & Me.LstHisNom.List(x, 7)

'Validar que el Monto sea positivo


If Val(Me.LstHisNom.List(x, 7)) > 0 Then

'acumular el monto al mes correspondiente


If ActMes = 1 Then TotalEne = TotalEne + Val(Me.LstHisNom.List(x, 7))
If ActMes = 2 Then TotalFeb = TotalFeb + Val(Me.LstHisNom.List(x, 7))
If ActMes = 3 Then TotalMar = TotalMar + Val(Me.LstHisNom.List(x, 7))
If ActMes = 4 Then TotalAbr = TotalAbr + Val(Me.LstHisNom.List(x, 7))
If ActMes = 5 Then TotalMay = TotalMay + Val(Me.LstHisNom.List(x, 7))
If ActMes = 6 Then TotalJun = TotalJun + Val(Me.LstHisNom.List(x, 7))
If ActMes = 7 Then TotalJul = TotalJul + Val(Me.LstHisNom.List(x, 7))
If ActMes = 8 Then TotalAgo = TotalAgo + Val(Me.LstHisNom.List(x, 7))
If ActMes = 9 Then TotalSep = TotalSep + Val(Me.LstHisNom.List(x, 7))

' Acumular valor de los meses


TotalAcu = TotalAcu + Val(Me.LstHisNom.List(x, 7))

'Actualiza el Mes en proceso


ActMes = Val(Me.LstHisNom.List(x, 3))
End If 'valido que el valor sea positvo (valor > 0)
End If 'valido movimiento Producido

If Val(Me.LstHisNom.List(x, 0)) = 5880 Then MsgBox "el Movimieno es: " &
Me.LstHisNom.List(x, 13) & " Por: " & Me.LstHisNom.List(x, 7)

Else
'Mover el empleado procesado (ActEmpID) y sus Totales por mes y el Total
acumulado
'Agrega las generales del empleado al List de Bonificaci�n
' If TotalAcu > 0 Then
Me.LstBonEmp.AddItem
Me.LstBonEmp.List(i, 0) = Str(i)
Me.LstBonEmp.List(i, 1) = ActEmpID
Me.LstBonEmp.List(i, 2) = BuscarEmpNom(ActEmpID)
Me.LstBonEmp.List(i, 3) = BuscarEmpCed(ActEmpID)
Me.LstBonEmp.List(i, 4) = BuscarEmpDep(ActEmpID) 'Me.LstHisNom.List(i, 17)
Me.LstBonEmp.List(i, 5) = Format(BuscarEmpFin(ActEmpID), "dd/mm/yyyy") 'Buscar
Fecha de Ingreso
Me.LstBonEmp.List(i, 6) = Format(BuscarEmpFsa(ActEmpID), "dd/mm/yyyy") 'Buscar
Fecha de Salida
Me.LstBonEmp.List(i, 7) = Format(TotalEne, "#,##0.00")
Me.LstBonEmp.List(i, 8) = Format(TotalFeb, "#,##0.00")

Me.LstBonEmp.List(i, 9) = Format(TotalMar, "#,##0.00")


Me.LstBonEmp.List(i, 10) = Format(TotalAbr, "#,##0.00")
Me.LstBonEmp.List(i, 11) = Format(TotalMay, "#,##0.00")
Me.LstBonEmp.List(i, 12) = Format(TotalJun, "#,##0.00")
Me.LstBonEmp.List(i, 13) = Format(TotalJul, "#,##0.00")
Me.LstBonEmp.List(i, 14) = Format(TotalAgo, "#,##0.00")
Me.LstBonEmp.List(i, 15) = Format(TotalSep, "#,##0.00")

'Presentar el Acumulado en la lista


Me.LstBonEmp.List(i, 16) = Format(TotalAcu, "#,##0.00")
' End If
'Actualizar el empleado
ActEmpID = Me.LstHisNom.List(x, 0)
'Incrementa el contador de empleados
i = i + 1

'Inicializa las variables para los totales por empleado en los meses y el
acumulado
TotalEne = 0
TotalFeb = 0
TotalMar = 0
TotalAbr = 0
TotalMay = 0
TotalJun = 0
TotalJul = 0
TotalAgo = 0
TotalSep = 0
TotalAcu = 0
End If 'valido empleado

Next x
'Agrega los Totales
'LblTotIng.Caption = Format(TotalIngresos, "#,##0.00")
'LblTotDsc.Caption = Format(TotalDescuentos, "#,##0.00")
'LblNetPag.Caption = Format((TotalIngresos - TotalDescuentos), "#,##0.00")
End Sub

Function BuscarEmpNom(EmpID As String) As String


'inicializa la funci�n
BuscarEmpNom = ""
'Buscar la Nombre en el Maestro de Empleados
For x = 0 To Me.LstMasEmp.ListCount - 1
If Val(Me.LstMasEmp.List(x, 0)) = Val(EmpID) Then
BuscarEmpNom = Me.LstMasEmp.List(x, 1) & " " & Me.LstMasEmp.List(x, 2)
End If
Next x
End Function

Function BuscarEmpCed(EmpID As String) As String


'inicializa la funci�n
BuscarEmpCed = ""
'Buscar la c�dula en el Maestro de Empleados
For x = 0 To Me.LstMasEmp.ListCount - 1
If Val(Me.LstMasEmp.List(x, 0)) = Val(EmpID) Then
BuscarEmpCed = Me.LstMasEmp.List(x, 4)

End If
Next x
End Function

Function BuscarEmpDep(EmpID As String) As String


'inicializa la funci�n
BuscarEmpDep = ""
'Buscar Depto. en el Maestro de Empleados
For x = 0 To Me.LstMasEmp.ListCount - 1
If Val(Me.LstMasEmp.List(x, 0)) = Val(EmpID) Then
BuscarEmpDep = Me.LstMasEmp.List(x, 6)

End If
Next x
End Function

Function BuscarEmpFin(EmpID As String) As String


'inicializa la funci�n
BuscarEmpFin = ""
'Buscar La fecha de ingreso en el Maestro de Empleados
For x = 0 To Me.LstMasEmp.ListCount - 1
If Val(Me.LstMasEmp.List(x, 0)) = Val(EmpID) Then
BuscarEmpFin = Me.LstMasEmp.List(x, 14)
End If
Next x
End Function
Function BuscarEmpFsa(EmpID As String) As String
'inicializa la funci�n
BuscarEmpFsa = ""
'Buscar La fecha de salida en el Maestro de Empleados
For x = 0 To Me.LstMasEmp.ListCount - 1
If Val(Me.LstMasEmp.List(x, 0)) = Val(EmpID) Then
BuscarEmpFsa = Me.LstMasEmp.List(x, 18)
End If
Next x
End Function

You might also like