Una Nueva Idea para una Macro ya existe

Dante Amor

Me ayudaste con esta nueva macro

Sub CopiarDatos2()
'Por.Dante Amor
    Set h1 = Sheets("Registro_Procedimiento")
    Set h2 = Sheets("AC")
    u = h2.Range("B" & Rows.Count).End(xlUp).Row + 1
    h2.Cells(u, "B") = "'682760382901"
    h2.Cells(u, "C") = h1.Range("C7")
    h2.Cells(u, "D") = h1.Range("C8")
    h2.Cells(u, "E") = h1.Range("C13")
    h2.Cells(u, "F") = h1.Range("C14")
    h2.Cells(u, "J") = "'1"
    If h1.Range("C14") = 890202 Then
        h2.Cells(u, "K") = "'48100"
    ElseIf h1.Range("C14") = 890302 Then
        h2.Cells(u, "K") = "'32450"
    End If
    MsgBox "Registro copiado"
End Sub

Pero se me acaba de ocurrir una nueva idea que me gustaría que me ayudaras. Como esos valores de 48100 y de 32450 cambian cada año, para no tener que estarme metiendo a modificar esos valores en la macro, que tal si los tomamos de la una nueva hoja que tengo llamada "constantes" y en la celda "J2" pongo lo correspondiente al 890202 y en la celda "K2" pongo lo correspondiente al 890302, de esa manera como seria nueva Macro?

1 respuesta

Respuesta
1

 H o l a:

Te anexo la macro

Sub CopiarDatos2()
'Por.Dante Amor
    Set h1 = Sheets("Registro_Procedimiento")
    Set h2 = Sheets("AC")
    Set h3 = Sheets("constantes")
    u = h2.Range("B" & Rows.Count).End(xlUp).Row + 1
    h2.Cells(u, "B") = "'682760382901"
    h2.Cells(u, "C") = h1.Range("C7")
    h2.Cells(u, "D") = h1.Range("C8")
    h2.Cells(u, "E") = h1.Range("C13")
    h2.Cells(u, "F") = h1.Range("C14")
    h2.Cells(u, "J") = "'1"
    If h1.Range("C14") = 890202 Then
        h2.Cells(u, "K") = h3.[J2]
    ElseIf h1.Range("C14") = 890302 Then
        h2.Cells(u, "K") = h3.[K2]
    End If
    MsgBox "Registro copiado"
End Sub

S a l u d o s

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas