Macros excel. 3 puntos importantes: Sobrescribir, insertar y ceros a la izquierda

Estoy desarrollando una macro que traspasa los datos de una Hoja BASE a otras siempre y cuando cumplan con una determinada condición.

Esta parte esta resuelta sin embargo me enfrento a tres problemas:

1.- El archivo cuenta con clabes interbancarias las cuales tienen 0021XXXXXXXXXXXXXX a la izquierda--> al aplicar la macro esta los trapasa como 2.1XXXE+15

2.- Al dar clic dos veces en el botón al que asigne la macro, transcribe debajo de lo que ya traspase, deseo que se sobrescriba con la información que actualice.

3.- Deseo que al insertar una fila en la BASE, se copien FORMULAS y el formato condicional que establecí.

Sub transferirdatos()
Dim IMSS As String
Dim Puesto As String
Dim FechaIngreso As Date
Dim Empleado As String
Dim Banco As String
Dim Cuenta As String
Dim Clabe As String
Dim EmpresaSC As String
Dim EmpresaSS As String
Dim TPrepago As String
Dim SueldoMensual As Integer
Dim SalarioDiario As Integer
Dim Dias As Integer
Dim SueldoQuincenal As Integer
Dim PagosExtras As Integer
Dim DescuentosFastFin As Integer
Dim DescuentosInfonavit As Integer
Dim SeguridadSocial As Integer
Dim TPrepago2 As Integer
Dim Efectivo As Integer
Dim SC As Integer
Dim TotalAPagar As Integer
Dim CSC As String
Dim CTPP As String
Dim CEFE As String
Dim CINTER As String
Dim UltimaFila As Long
Dim UltimaFilaIMSS As Long
Dim UltimaFilaSC As Long
Dim UltimaFilaSCINTERBANCARIAS As Long
Dim UltimaFilaTPP As Long
Dim UltimaFilaEFECTIVO As Long
Dim Cont As Long
Dim Palabra1 As String
Palabra1 = Sheets("BASE").Cells(10, 28)
UltimaFila = Sheets("BASE").Range("H" & Rows.Count).End(xlUp).Row
If UltimaFila < 14 Then
Exit Sub
End If
For Cont = 14 To UltimaFila
End If
If Sheets("BASE").Cells(Cont, 31) = Palabra1 Then
IMSS = Sheets("BASE").Cells(Cont, 5)
Puesto = Sheets("BASE").Cells(Cont, 6)
FechaIngreso = Sheets("BASE").Cells(Cont, 7)
Empleado = Sheets("BASE").Cells(Cont, 8)
Banco = Sheets("BASE").Cells(Cont, 9)
Cuenta = Sheets("BASE").Cells(Cont, 10)
Clabe = Sheets("BASE").Cells(Cont, 11)
EmpresaSC = Sheets("BASE").Cells(Cont, 12)
EmpresaSS = Sheets("BASE").Cells(Cont, 13)
TPrepago = Sheets("BASE").Cells(Cont, 14)
SueldoMensual = Sheets("BASE").Cells(Cont, 15)
SalarioDiario = Sheets("BASE").Cells(Cont, 16)
Dias = Sheets("BASE").Cells(Cont, 17)
SueldoQuincenal = Sheets("BASE").Cells(Cont, 18)
PagosExtras = Sheets("BASE").Cells(Cont, 19)
DescuentosFastFin = Sheets("BASE").Cells(Cont, 20)
DescuentosInfonavit = Sheets("BASE").Cells(Cont, 21)
SeguridadSocial = Sheets("BASE").Cells(Cont, 22)
TPrepago2 = Sheets("BASE").Cells(Cont, 23)
Efectivo = Sheets("BASE").Cells(Cont, 24)
SC = Sheets("BASE").Cells(Cont, 25)
TotalAPagar = Sheets("BASE").Cells(Cont, 26)
CSC = Sheets("BASE").Cells(Cont, 28)
CTPP = Sheets("BASE").Cells(Cont, 29)
CEFE = Sheets("BASE").Cells(Cont, 30)
CINTER = Sheets("BASE").Cells(Cont, 31)
UltimaFilaSCINTERBANCARIAS = Sheets("SCINTERBANCARIAS").Range("G" & Rows.Count).End(xlUp).Row
Sheets("SCINTERBANCARIAS").Cells(UltimaFilaSCINTERBANCARIAS + 1, 2) = EmpresaSC
Sheets("SCINTERBANCARIAS").Cells(UltimaFilaSCINTERBANCARIAS + 1, 3) = Banco
Sheets("SCINTERBANCARIAS").Cells(UltimaFilaSCINTERBANCARIAS + 1, 4) = Clabe
Sheets("SCINTERBANCARIAS").Cells(UltimaFilaSCINTERBANCARIAS + 1, 6) = SC
Sheets("SCINTERBANCARIAS").Cells(UltimaFilaSCINTERBANCARIAS + 1, 7) = Empleado
End If
Next Cont
End Sub

1 Respuesta

Respuesta
1

Para dejar la Clabe como texto puedes cambiar esta línea:

Clabe = Sheets("BASE").Cells(Cont, 11)

Por esta :

Clabe = "'" & Sheets("BASE").Cells(Cont, 11)

De esa forma quedará almacenado como texto y no perderás dígitos.


No se copió completa tu macro, porque tienes un End If después del For Cont = 14 To UltimaFila, eso te debe marcar un error. 


Necesito que me expliques en qué momento o qué características deben tener los datos para sobreescribir y en qué momento o qué características deben tener los datos para insertar un nuevo registro.

Resolvemos los primeros 2 puntos y después vemos el punto 3.

Hola Dante!

Excelente aportación! Muchas gracias!

Con respecto a lo demás, al dar clic en el botón al que asigne la macro, se traspasan los datos de manera correcta, pero al dar de nuevo clic la información se repite debajo de la última fila, como en la última imagen donde están los nombres de René y Amador junto con los demás datos, en lugar de esto, deseo que se reescriba lo que modifique en la base es decir, si modifique el monto de $10 a $20 que no me aparezca en monto E2 = rene $10 E3 = amador $10 E4 = rene $20 amador $20  , si modifico algún dato aparezcan en la misma fila en este ejemplo E2 Y E3....

y con respecto al insertar filas quiero que no queden en blanco, si no que se copien las formulas :

Sub transferirdatos()
Dim IMSS As String
Dim Puesto As String
Dim FechaIngreso As Date
Dim Empleado As String
Dim Banco As String
Dim Cuenta As String
Dim Clabe As String
Dim EmpresaSC As String
Dim EmpresaSS As String
Dim TPrepago As String
Dim SueldoMensual As Integer
Dim SalarioDiario As Integer
Dim Dias As Integer
Dim SueldoQuincenal As Integer
Dim PagosExtras As Integer
Dim DescuentosFastFin As Integer
Dim DescuentosInfonavit As Integer
Dim SeguridadSocial As Integer
Dim TPrepago2 As Integer
Dim Efectivo As Integer
Dim SC As Integer
Dim TotalAPagar As Integer
Dim CSC As String
Dim CTPP As String
Dim CEFE As String
Dim CINTER As String
Dim UltimaFila As Long
Dim UltimaFilaIMSS As Long
Dim UltimaFilaSC As Long
Dim UltimaFilaSCINTERBANCARIAS As Long
Dim UltimaFilaTPP As Long
Dim UltimaFilaEFECTIVO As Long
Dim Cont As Long
Dim Palabra1 As String
Palabra1 = Sheets("BASE").Cells(10, 28)
UltimaFila = Sheets("BASE").Range("H" & Rows.Count).End(xlUp).Row
If UltimaFila < 14 Then
Exit Sub
End If
For Cont = 14 To UltimaFila
If Sheets("BASE").Cells(Cont, 5) = Palabra1 Then
IMSS = Sheets("BASE").Cells(Cont, 5)
Puesto = Sheets("BASE").Cells(Cont, 6)
FechaIngreso = Sheets("BASE").Cells(Cont, 7)
Empleado = Sheets("BASE").Cells(Cont, 8)
Banco = Sheets("BASE").Cells(Cont, 9)
Cuenta = "'" & Sheets("BASE").Cells(Cont, 10)
Clabe = "'" & Sheets("BASE").Cells(Cont, 11)
EmpresaSC = Sheets("BASE").Cells(Cont, 12)
EmpresaSS = Sheets("BASE").Cells(Cont, 13)
TPrepago = Sheets("BASE").Cells(Cont, 14)
SueldoMensual = Sheets("BASE").Cells(Cont, 15)
SalarioDiario = Sheets("BASE").Cells(Cont, 16)
Dias = Sheets("BASE").Cells(Cont, 17)
SueldoQuincenal = Sheets("BASE").Cells(Cont, 18)
PagosExtras = Sheets("BASE").Cells(Cont, 19)
DescuentosFastFin = Sheets("BASE").Cells(Cont, 20)
DescuentosInfonavit = Sheets("BASE").Cells(Cont, 21)
SeguridadSocial = Sheets("BASE").Cells(Cont, 22)
TPrepago2 = Sheets("BASE").Cells(Cont, 23)
Efectivo = Sheets("BASE").Cells(Cont, 24)
SC = Sheets("BASE").Cells(Cont, 25)
TotalAPagar = Sheets("BASE").Cells(Cont, 26)
CSC = Sheets("BASE").Cells(Cont, 28)
CTPP = Sheets("BASE").Cells(Cont, 29)
CEFE = Sheets("BASE").Cells(Cont, 30)
CINTER = Sheets("BASE").Cells(Cont, 31)
UltimaFilaIMSS = Sheets("IMSS").Range("F" & Rows.Count).End(xlUp).Row
Sheets("IMSS").Cells(UltimaFilaIMSS + 1, 2) = EmpresaSS
Sheets("IMSS").Cells(UltimaFilaIMSS + 1, 3) = Banco
Sheets("IMSS").Cells(UltimaFilaIMSS + 1, 4) = Cuenta
Sheets("IMSS").Cells(UltimaFilaIMSS + 1, 5) = SeguridadSocial
Sheets("IMSS").Cells(UltimaFilaIMSS + 1, 6) = Empleado
End If
If Sheets("BASE").Cells(Cont, 28) = Palabra1 Then
IMSS = Sheets("BASE").Cells(Cont, 5)
Puesto = Sheets("BASE").Cells(Cont, 6)
FechaIngreso = Sheets("BASE").Cells(Cont, 7)
Empleado = Sheets("BASE").Cells(Cont, 8)
Banco = Sheets("BASE").Cells(Cont, 9)
Cuenta = "'" & Sheets("BASE").Cells(Cont, 10)
Clabe = "'" & Sheets("BASE").Cells(Cont, 11)
EmpresaSC = Sheets("BASE").Cells(Cont, 12)
EmpresaSS = Sheets("BASE").Cells(Cont, 13)
TPrepago = Sheets("BASE").Cells(Cont, 14)
SueldoMensual = Sheets("BASE").Cells(Cont, 15)
SalarioDiario = Sheets("BASE").Cells(Cont, 16)
Dias = Sheets("BASE").Cells(Cont, 17)
SueldoQuincenal = Sheets("BASE").Cells(Cont, 18)
PagosExtras = Sheets("BASE").Cells(Cont, 19)
DescuentosFastFin = Sheets("BASE").Cells(Cont, 20)
DescuentosInfonavit = Sheets("BASE").Cells(Cont, 21)
SeguridadSocial = Sheets("BASE").Cells(Cont, 22)
TPrepago2 = Sheets("BASE").Cells(Cont, 23)
Efectivo = Sheets("BASE").Cells(Cont, 24)
SC = Sheets("BASE").Cells(Cont, 25)
TotalAPagar = Sheets("BASE").Cells(Cont, 26)
CSC = Sheets("BASE").Cells(Cont, 28)
CTPP = Sheets("BASE").Cells(Cont, 29)
CEFE = Sheets("BASE").Cells(Cont, 30)
CINTER = Sheets("BASE").Cells(Cont, 31)
UltimaFilaSC = Sheets("SC").Range("F" & Rows.Count).End(xlUp).Row
Sheets("SC").Cells(UltimaFilaSC + 1, 2) = EmpresaSC
Sheets("SC").Cells(UltimaFilaSC + 1, 3) = Banco
Sheets("SC").Cells(UltimaFilaSC + 1, 4) = Cuenta
Sheets("SC").Cells(UltimaFilaSC + 1, 5) = SC
Sheets("SC").Cells(UltimaFilaSC + 1, 6) = Empleado
End If
If Sheets("BASE").Cells(Cont, 29) = Palabra1 Then
IMSS = Sheets("BASE").Cells(Cont, 5)
Puesto = Sheets("BASE").Cells(Cont, 6)
FechaIngreso = Sheets("BASE").Cells(Cont, 7)
Empleado = Sheets("BASE").Cells(Cont, 8)
Banco = Sheets("BASE").Cells(Cont, 9)
Cuenta = "'" & Sheets("BASE").Cells(Cont, 10)
Clabe = "'" & Sheets("BASE").Cells(Cont, 11)
EmpresaSC = Sheets("BASE").Cells(Cont, 12)
EmpresaSS = Sheets("BASE").Cells(Cont, 13)
TPrepago = Sheets("BASE").Cells(Cont, 14)
SueldoMensual = Sheets("BASE").Cells(Cont, 15)
SalarioDiario = Sheets("BASE").Cells(Cont, 16)
Dias = Sheets("BASE").Cells(Cont, 17)
SueldoQuincenal = Sheets("BASE").Cells(Cont, 18)
PagosExtras = Sheets("BASE").Cells(Cont, 19)
DescuentosFastFin = Sheets("BASE").Cells(Cont, 20)
DescuentosInfonavit = Sheets("BASE").Cells(Cont, 21)
SeguridadSocial = Sheets("BASE").Cells(Cont, 22)
TPrepago2 = Sheets("BASE").Cells(Cont, 23)
Efectivo = Sheets("BASE").Cells(Cont, 24)
SC = Sheets("BASE").Cells(Cont, 25)
TotalAPagar = Sheets("BASE").Cells(Cont, 26)
CSC = Sheets("BASE").Cells(Cont, 28)
CTPP = Sheets("BASE").Cells(Cont, 29)
CEFE = Sheets("BASE").Cells(Cont, 30)
CINTER = Sheets("BASE").Cells(Cont, 31)
UltimaFilaTPP = Sheets("TPP").Range("D" & Rows.Count).End(xlUp).Row
Sheets("TPP").Cells(UltimaFilaTPP + 1, 2) = TPrepago
Sheets("TPP").Cells(UltimaFilaTPP + 1, 3) = TPrepago2
Sheets("TPP").Cells(UltimaFilaTPP + 1, 4) = Empleado
End If
If Sheets("BASE").Cells(Cont, 30) = Palabra1 Then
IMSS = Sheets("BASE").Cells(Cont, 5)
Puesto = Sheets("BASE").Cells(Cont, 6)
FechaIngreso = Sheets("BASE").Cells(Cont, 7)
Empleado = Sheets("BASE").Cells(Cont, 8)
Banco = Sheets("BASE").Cells(Cont, 9)
Cuenta = "'" & Sheets("BASE").Cells(Cont, 10)
Clabe = "'" & Sheets("BASE").Cells(Cont, 11)
EmpresaSC = Sheets("BASE").Cells(Cont, 12)
EmpresaSS = Sheets("BASE").Cells(Cont, 13)
TPrepago = Sheets("BASE").Cells(Cont, 14)
SueldoMensual = Sheets("BASE").Cells(Cont, 15)
SalarioDiario = Sheets("BASE").Cells(Cont, 16)
Dias = Sheets("BASE").Cells(Cont, 17)
SueldoQuincenal = Sheets("BASE").Cells(Cont, 18)
PagosExtras = Sheets("BASE").Cells(Cont, 19)
DescuentosFastFin = Sheets("BASE").Cells(Cont, 20)
DescuentosInfonavit = Sheets("BASE").Cells(Cont, 21)
SeguridadSocial = Sheets("BASE").Cells(Cont, 22)
TPrepago2 = Sheets("BASE").Cells(Cont, 23)
Efectivo = Sheets("BASE").Cells(Cont, 24)
SC = Sheets("BASE").Cells(Cont, 25)
TotalAPagar = Sheets("BASE").Cells(Cont, 26)
CSC = Sheets("BASE").Cells(Cont, 28)
CTPP = Sheets("BASE").Cells(Cont, 29)
CEFE = Sheets("BASE").Cells(Cont, 30)
CINTER = Sheets("BASE").Cells(Cont, 31)
UltimaFilaEFECTIVO = Sheets("EFECTIVO").Range("C" & Rows.Count).End(xlUp).Row
Sheets("EFECTIVO").Cells(UltimaFilaEFECTIVO + 1, 2) = Efectivo
Sheets("EFECTIVO").Cells(UltimaFilaEFECTIVO + 1, 3) = Empleado
End If
If Sheets("BASE").Cells(Cont, 31) = Palabra1 Then
IMSS = Sheets("BASE").Cells(Cont, 5)
Puesto = Sheets("BASE").Cells(Cont, 6)
FechaIngreso = Sheets("BASE").Cells(Cont, 7)
Empleado = Sheets("BASE").Cells(Cont, 8)
Banco = Sheets("BASE").Cells(Cont, 9)
Cuenta = "'" & Sheets("BASE").Cells(Cont, 10)
Clabe = "'" & Sheets("BASE").Cells(Cont, 11)
EmpresaSC = Sheets("BASE").Cells(Cont, 12)
EmpresaSS = Sheets("BASE").Cells(Cont, 13)
TPrepago = Sheets("BASE").Cells(Cont, 14)
SueldoMensual = Sheets("BASE").Cells(Cont, 15)
SalarioDiario = Sheets("BASE").Cells(Cont, 16)
Dias = Sheets("BASE").Cells(Cont, 17)
SueldoQuincenal = Sheets("BASE").Cells(Cont, 18)
PagosExtras = Sheets("BASE").Cells(Cont, 19)
DescuentosFastFin = Sheets("BASE").Cells(Cont, 20)
DescuentosInfonavit = Sheets("BASE").Cells(Cont, 21)
SeguridadSocial = Sheets("BASE").Cells(Cont, 22)
TPrepago2 = Sheets("BASE").Cells(Cont, 23)
Efectivo = Sheets("BASE").Cells(Cont, 24)
SC = Sheets("BASE").Cells(Cont, 25)
TotalAPagar = Sheets("BASE").Cells(Cont, 26)
CSC = Sheets("BASE").Cells(Cont, 28)
CTPP = Sheets("BASE").Cells(Cont, 29)
CEFE = Sheets("BASE").Cells(Cont, 30)
CINTER = Sheets("BASE").Cells(Cont, 31)
UltimaFilaSCINTERBANCARIAS = Sheets("SCINTERBANCARIAS").Range("G" & Rows.Count).End(xlUp).Row
Sheets("SCINTERBANCARIAS").Cells(UltimaFilaSCINTERBANCARIAS + 1, 2) = EmpresaSC
Sheets("SCINTERBANCARIAS").Cells(UltimaFilaSCINTERBANCARIAS + 1, 3) = Banco
Sheets("SCINTERBANCARIAS").Cells(UltimaFilaSCINTERBANCARIAS + 1, 4) = Clabe
Sheets("SCINTERBANCARIAS").Cells(UltimaFilaSCINTERBANCARIAS + 1, 6) = SC
Sheets("SCINTERBANCARIAS").Cells(UltimaFilaSCINTERBANCARIAS + 1, 7) = Empleado
End If
Next Cont
End Sub

No entiendo porqué revisas el nombre en diferentes columnas.

Mejor envíame tu archivo y me explicas con un ejemplo cuando es nuevo y cuando es modificación.

Mi correo [email protected]

En el asunto del correo escribe tu nombre de usuario “Alfonso Sierra

Te anexo la macro

Sub Transferencias()
'Por Dante Amor
    Application.ScreenUpdating = False
    Set h1 = Sheets("BASE")
    Set h2 = Sheets("IMSS")
    Set h3 = Sheets("SC")
    Set h4 = Sheets("SCINTERBANCARIAS")
    Set h5 = Sheets("TPP")
    Set h6 = Sheets("EFECTIVO")
    '
    H2.Range("B9:F" & Rows. Count). ClearContents
 h3.Range("B9:F" & Rows. Count). ClearContents
 h4.Range("B9:G" & Rows. Count). ClearContents
 h5.Range("B9:D" & Rows. Count). ClearContents
 h6.Range("B9:C" & Rows. Count). ClearContents
    '
    For i = 14 To h1.Range("E" & Rows.Count).End(xlUp).Row
        IMSS = h1.Cells(i, 5)
        Puesto = h1.Cells(i, 6)
        FechaIngreso = h1.Cells(i, 7)
        Empleado = h1.Cells(i, 8)
        Banco = h1.Cells(i, 9)
        Cuenta = "'" & h1.Cells(i, 10)
        Clabe = "'" & h1.Cells(i, 11)
        EmpresaSC = h1.Cells(i, 12)
        EmpresaSS = h1.Cells(i, 13)
        TPrepago = h1.Cells(i, 14)
        SueldoMensual = h1.Cells(i, 15)
        SalarioDiario = h1.Cells(i, 16)
        Dias = h1.Cells(i, 17)
        SueldoQuincenal = h1.Cells(i, 18)
        PagosExtras = h1.Cells(i, 19)
        DescuentosFastFin = h1.Cells(i, 20)
        DescuentosInfonavit = h1.Cells(i, 21)
        SeguridadSocial = h1.Cells(i, 22)
        TPrepago2 = h1.Cells(i, 23)
        Efectivo = h1.Cells(i, 24)
        SC = h1.Cells(i, 25)
        TotalAPagar = h1.Cells(i, 26)
        CSC = h1.Cells(i, 28)
        CTPP = h1.Cells(i, 29)
        CEFE = h1.Cells(i, 30)
        CINTER = h1.Cells(i, 31)
        '
        If h1.Cells(i, "E") = "OK" Then 'imss
            u = h2.Range("F" & Rows.Count).End(xlUp).Row + 1
            h2.Cells(u, 2) = EmpresaSS
            h2.Cells(u, 3) = Banco
            h2.Cells(u, 4) = Cuenta
            h2.Cells(u, 5) = SeguridadSocial
            h2.Cells(u, 6) = Empleado
        End If
        If h1.Cells(i, 28) = "OK" Then 'sc
            u = h3.Range("F" & Rows.Count).End(xlUp).Row + 1
            h3.Cells(u, 2) = EmpresaSC
            h3.Cells(u, 3) = Banco
            h3.Cells(u, 4) = Cuenta
            h3.Cells(u, 5) = SC
            h3.Cells(u, 6) = Empleado
        End If
        If h1.Cells(i, 31) = "OK" Then 'inter
            u = h4.Range("G" & Rows.Count).End(xlUp).Row + 1
            h4.Cells(u, 2) = EmpresaSC
            h4.Cells(u, 3) = Banco
            h4.Cells(u, 4) = Clabe
            h4.Cells(u, 6) = SC
            h4.Cells(u, 7) = Empleado
        End If
        If h1.Cells(i, 29) = "OK" Then 'tpp
            u = h5.Range("D" & Rows.Count).End(xlUp).Row + 1
            h5.Cells(u, 2) = TPrepago
            h5.Cells(u, 3) = TPrepago2
            h5.Cells(u, 4) = Empleado
        End If
        If h1.Cells(i, 30) = "OK" Then 'efectivo
            u = h6.Range("C" & Rows.Count).End(xlUp).Row + 1
            h6.Cells(u, 2) = Efectivo
            h6.Cells(u, 3) = Empleado
        End If
    Next
    Application.ScreenUpdating = True
    MsgBox "Fin"
End Sub

.

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

.

Avísame cualquier duda

.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas