The macro has this problem:
If Monica buys only flowers (see image 1), then on Sheet 2 she inserts 4 empty rows.
If Monica buys only flowers and wrapping paper, then on Sheet 2 she inserts 3 empty rows.
If Monica buys only flowers, gift wrap and a card, then on Sheet 2 she inserts 2 rows (see image 2).
How can I make it so that the macro does not insert empty rows in Sheet 2?
Sub Compras_del_Cliente()
'Compras del cliente Macro
Sheets("Hoja2").Select
Range("A9:A13").EntireRow.Insert
'Nombre / Empresa
Sheets("Hoja1").Select
Range("C9").Copy
Sheets("Hoja2").Select
Range("A9").PasteSpecial xlPasteValues
'Código
Sheets("Hoja1").Select
If Range("B12:B16").Select <> Empty Then
Range("B12:B16").Copy
End If
Sheets("Hoja2").Select
Range("C9").PasteSpecial xlPasteValues
'Descripción del Producto
Sheets("Hoja1").Select
If Range("C12:C16").Select <> Empty Then
Range("C12:C16").Copy
End If
Sheets("Hoja2").Select
Range("B9").PasteSpecial xlPasteValues
'Cantidad
Sheets("Hoja1").Select
If Range("D12:D16").Select <> Empty Then
Range("D12:D16").Copy
End If
Sheets("Hoja2").Select
Range("D9").PasteSpecial xlPasteValues
'Precio
Sheets("Hoja1").Select
If Range("E12:E16").Select <> Empty Then
Range("E12:E16").Copy
End If
Sheets("Hoja2").Select
Range("E9").PasteSpecial xlPasteValues
End Sub
Sub Borrar()
'Botón para borrar valores en la tabla "Compras del CLIENTE" en Hoja 1
Range("C9").Value = Empty
Range("B12:B16").Value = Empty
Range("C12:C16").Value = Empty
Range("D12:D16").Value = Empty
Range("E12:E16").Value = Empty
End Sub
Sub Eliminar_venta()
'Botón para eliminar venta en la tabla "Lista de VENTAS" en la Hoja 2
Sheets("Hoja2").Select
Selection.EntireRow.Delete
End Sub
In this part of the code, you are saying that if there is any data in the range of cells, from B12 to B16, that is, it is different from Empty, copy the entire range and paste it on sheet 2 from cell C9
You are not saying to copy the cells with data, you are saying that if there is data in any cell, copy them all.
You are copying 5 rows regardless of whether there is data in one (flowers), two (flowers and paper) or three (flowers, paper and cards). Since you copy the five rows, it will paste the rows with data and the empty rows, hence it will paste those blank lines that you say.
The way to avoid it, would be to evaluate row by row, if there is data that you copy the cell with data.
You could create a loop that validates that in the range of rows it finds data, if it finds it, copy it and paste it on sheet 2