Ayuda Macro planilla sueldos

Buen dia Dam. Necesito de tu ayuda nuevamente para que me modifiques un macro que realizaste para que se aplique sobre otra planilla de sueldos con orden distinto a la que anteriormente me has ayudado.

Este es el código

---------------- CÓDIGO ---------------

Sub Planilla_Gral_MI()
Set hactual = Sheets(3)
Dim xfecha
xfecha = InputBox("Ingrese fecha a procesar en formato mm/aaaa")
Set hdest = Sheets.Add
ActiveSheet.Name = "Planilla_gral_MI"
hactual.Select
ufila = Range("A" & Rows.Count).End(xlUp).Row
ucol = ActiveCell.SpecialCells(xlLastCell).Column
hdest.Columns("C").NumberFormat = "mm\/yyyy"
j = 1
For k = 8 To ucol
If IsNumeric(hactual.Cells(1, k)) And hactual.Cells(1, k) <> "" And hactual.Cells(2, k) = "MI" Then
For i = 7 To ufila
If Cells(i, 1) <> "" Then
hdest.Cells(j, 1) = "'" & hactual.Cells(1, k)
hdest.Cells(j, 2) = "'" & hactual.Cells(i, 1)
hdest.Cells(j, 3) = xfecha
If hactual.Cells(i, k) = "" _
Or Not IsNumeric(hactual.Cells(i, k)) Then
hdest.Cells(j, 4) = 0
Else
hdest.Cells(j, 4) = hactual.Cells(i, k)
End If
j = j + 1
End If
Next
End If
Next
hdest.Select
MsgBox "Planilla General exportada correctamente..."
End Sub

------------------------- FIN CÓDIGO ------------------------

El macro tiene que tomar los valores de otro lugar de la planilla como te lo muestro en la siguiente imagen:

http://dl.dropbox.com/u/31683777/Planilla%20Gral.PNG

Asi es como debería quedar el archivo generado después de aplicar el nuevo macro:

http://dl.dropbox.com/u/31683777/exportado%20gral.PNG

Tengo que tener 2 Macros, uno para la empresa MI y el otro para XT.

Entonces los empleados que tengan en la columna F la palabra MI deberían tomar los valores de la Fila 4 comenzando por la columna 8 (esto es para el macro empresa MI).

Y si la columna F tiene la palabra XT debería tomar los valores de la fila 5 comenzando por la columna 8 (esto es para el macro empresa XT).

Las celdas vacías deben tener valor CERO como lo hace el código de arriba.

**Espero haber explicado de la mejor manera lo que necesito. Gracias***

1 respuesta

Respuesta
1

Te anexo las 2 macros

Para la empresa MI

Sub Planilla_Gral_MI()
Set hactual = Sheets(3)
Dim xfecha
xfecha = InputBox("Ingrese fecha a procesar en formato mm/aaaa")
Set hdest = Sheets.Add
ActiveSheet.Name = "Planilla_gral_MI"
hactual.Select
ufila = Range("A" & Rows.Count).End(xlUp).Row
ucol = ActiveCell.SpecialCells(xlLastCell).Column
hdest.Columns("C").NumberFormat = "mm\/yyyy"
j = 1
For i = 6 To ufila
If Cells(i, "B") <> "" Then
For k = 8 To ucol
    If IsNumeric(hactual.Cells(4, k)) And _
        hactual.Cells(4, k) <> "" And _
        hactual.Cells(4, "F") = "MI" Then
        hdest.Cells(j, 1) = "'" & hactual.Cells(i, "B")
        hdest.Cells(j, 2) = hactual.Cells(4, k)
        hdest.Cells(j, 3) = xfecha
        If hactual.Cells(i, k) = "" _
            Or Not IsNumeric(hactual.Cells(i, k)) Then
            hdest.Cells(j, 4) = 0
        Else
            hdest.Cells(j, 4) = hactual.Cells(i, k)
        End If
        j = j + 1
    End If
Next
End If
Next
hdest.Select
MsgBox "Planilla General exportada correctamente..."
End Sub

Para la empresa XT

Sub Planilla_Gral_XT()
Set hactual = Sheets(3)
Dim xfecha
xfecha = InputBox("Ingrese fecha a procesar en formato mm/aaaa")
Set hdest = Sheets.Add
ActiveSheet.Name = "Planilla_gral_XT"
hactual.Select
ufila = Range("A" & Rows.Count).End(xlUp).Row
ucol = ActiveCell.SpecialCells(xlLastCell).Column
hdest.Columns("C").NumberFormat = "mm\/yyyy"
j = 1
For i = 6 To ufila
If Cells(i, "B") <> "" Then
For k = 8 To ucol
    If IsNumeric(hactual.Cells(5, k)) And _
        hactual.Cells(5, k) <> "" And _
        hactual.Cells(5, "F") = "XT" Then
        hdest.Cells(j, 1) = "'" & hactual.Cells(i, "B")
        hdest.Cells(j, 2) = hactual.Cells(5, k)
        hdest.Cells(j, 3) = xfecha
        If hactual.Cells(i, k) = "" _
            Or Not IsNumeric(hactual.Cells(i, k)) Then
            hdest.Cells(j, 4) = 0
        Else
            hdest.Cells(j, 4) = hactual.Cells(i, k)
        End If
        j = j + 1
    End If
Next
End If
Next
hdest.Select
MsgBox "Planilla General exportada correctamente..."
End Sub

Prueba y me comentas.

Saludos. Dam

Si es lo que necesitas.

Gracias Dam, la macro estaba correcta, salvo unas cosas especificas que logre pillar y ahi recién me entrego los valores. Esto fue lo que corregui:

j = 1
For i = 6 To ufila
If Cells(i, "B") <> "" Then ' aquí lo corregí por (i, 2)
For k = 8 To ucol
If IsNumeric(hactual.Cells(4, k)) And _ ' y esta por (i, 2)
hactual.Cells(4, k) <> "" And _
hactual.Cells(4, "F") = "MI" Then ' esta por (i, 6)

Gracias compadre por tu ayuda, estoy muy agradecido.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas