• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Combine Macros

JUES

New Member
Good afternoon, everyone.

I currently have two macros that allow me to add rows (Sub Actualizar()) and delete rows (Sub Eliminar()). To do this, I have to click one of the two buttons at the top of Sheet 62 (FORMATO): the Update button (Image 11) and the Delete button (Image 12).

However, this procedure for adding and deleting rows in this way is confusing, so I need your help combining both macros so that only when I click the Update button (Image 11), the Delete macro (Sub Eliminar()) runs first, followed by the Update macro (Sub Actualizar()) .

I would greatly appreciate any help.
 

Attachments

  • Imagen11.png
    Imagen11.png
    4.1 KB · Views: 4
  • Imagen12.png
    Imagen12.png
    2.3 KB · Views: 4
  • PRUEBA CODIGOS.xlsm
    PRUEBA CODIGOS.xlsm
    88.8 KB · Views: 3
Greetings, my friend, thank you for your response.

I was reviewing how the macros work, and I think I inadvertently omitted some important information for them to function correctly:

First: The corresponding rows are correctly deleted in each table (the number of cells to delete is taken from cell CI23 to cell CP23).

Second: The corresponding rows are not added to each table (the number of cells to add is taken from cell CI21 to cell CP21).

Third: I need the execution of the macros `ActualizarTablas` and `EliminarTablas` to be triggered by a single button, which in this case should be the "Update" button.

Fourth: The following section of code must be included in the "Actualizar Tablas" macro so that the "Number of cells to Delete" (cell CI23 to cell CP23) can be updated, as well as the information from another table that is not shown in this file.

Code:
    Sheets("MATRIZ2").Select: Range("A3").EntireRow.Insert: Sheets("FORMATO").Select

    Range("C10").Copy: Sheets("MATRIZ2").Select: Range("C3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C11").Copy: Sheets("MATRIZ2").Select: Range("B3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C13").Copy: Sheets("MATRIZ2").Select: Range("D3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C15").Copy: Sheets("MATRIZ2").Select: Range("E3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C17").Copy: Sheets("MATRIZ2").Select: Range("F3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C19").Copy: Sheets("MATRIZ2").Select: Range("G3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C21").Copy: Sheets("MATRIZ2").Select: Range("H3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C23").Copy: Sheets("MATRIZ2").Select: Range("I3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C25").Copy: Sheets("MATRIZ2").Select: Range("J3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C27").Copy: Sheets("MATRIZ2").Select: Range("K3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C29").Copy: Sheets("MATRIZ2").Select: Range("L3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C31").Copy: Sheets("MATRIZ2").Select: Range("M3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C33").Copy: Sheets("MATRIZ2").Select: Range("N3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    Range("C35").Copy: Sheets("MATRIZ2").Select: Range("O3").PasteSpecial xlPasteValues: Sheets("FORMATO").Select

    'Copiar de Número de Filas a Agregar a Número de Filas a Eliminar

    'CEO
    Range("CI21").Copy: Sheets("USUARIOS & PRIVILEGIOS").Select: Range("CI23").PasteSpecial xlPasteValues: Sheets("USUARIOS & PRIVILEGIOS").Select

    'Tipo de Lugar
    Range("CJ21").Copy: Sheets("USUARIOS & PRIVILEGIOS").Select: Range("CJ23").PasteSpecial xlPasteValues: Sheets("USUARIOS & PRIVILEGIOS").Select

    'Actividad Física Especifica
    Range("CK21").Copy: Sheets("USUARIOS & PRIVILEGIOS").Select: Range("CK23").PasteSpecial xlPasteValues: Sheets("USUARIOS & PRIVILEGIOS").Select

    'Tipo de Trabajo
    Range("CL21").Copy: Sheets("USUARIOS & PRIVILEGIOS").Select: Range("CL23").PasteSpecial xlPasteValues: Sheets("USUARIOS & PRIVILEGIOS").Select

    'Agente Material
    Range("CM21").Copy: Sheets("USUARIOS & PRIVILEGIOS").Select: Range("CM23").PasteSpecial xlPasteValues: Sheets("USUARIOS & PRIVILEGIOS").Select

    'Tipo de Accidente
    Range("CN21").Copy: Sheets("USUARIOS & PRIVILEGIOS").Select: Range("CN23").PasteSpecial xlPasteValues: Sheets("USUARIOS & PRIVILEGIOS").Select

    'Parte del Cuerpo Lesionada
    Range("CO21").Copy: Sheets("USUARIOS & PRIVILEGIOS").Select: Range("CO23").PasteSpecial xlPasteValues: Sheets("USUARIOS & PRIVILEGIOS").Select

    'Naturaleza de la Lesión
    Range("CP21").Copy: Sheets("USUARIOS & PRIVILEGIOS").Select: Range("CP23").PasteSpecial xlPasteValues: Sheets("USUARIOS & PRIVILEGIOS").Select

Fifth: To obtain results consistent with the number of rows to delete (cell CI23 to cell CP23) and the number of rows to add (cell CI21 to cell CP21), I have modified the tables so that each one contains the following number of rows::

TablaEO = 2 rows
TablaTDL = 3 rows
TablaAFE = 4 rows
TablaTDT = 4 rows
TablaAM = 2 rows
TablaTDA = 4 rows
TablaPCL = 4 rows
TablaNDL = 3 rows

If the Eliminar Tablas macro is run, all tables should end with the following number of rows:

TablaEO = 2 rows
TablaTDL = 2 rows
TablaAFE = 2 rows
TablaTDT = 2 rows
TablaAM = 2 rows
TablaTDA = 2 rows
TablaPCL = 2 rows
TablaNDL = 2 rows

And if the macro Actualizar Tablas is then run, all tables should have the following number of rows:

TablaEO = 2 rows
TablaTDL = 3 rows
TablaAFE = 4 rows
TablaTDT = 4 rows
TablaAM = 2 rows
TablaTDA = 4 rows
TablaPCL = 4 rows
TablaNDL = 3 rows
 

Attachments

Last edited:
Back
Top