' Elimina el apartado correspondiente a las celdas seleccionadas
Sub EliminarApartados()
Dim fila, Columna As Long
Dim FilaInicial, FilaFinal As Long
Dim Error As Boolean
Dim i As Long
Error = False
fila = Selection.Row
Columna = Selection.Column
FilaInicial = fila
FilaFinal = fila
Do
If FilaInicial > 1 And HojaPresupuesto.Cells(FilaInicial, 2) <> "Total" Then
FilaInicial = FilaInicial - 1
Else
Error = True
Exit Do
End If
Loop While HojaPresupuesto.Cells(FilaInicial, 2) <> "Título"
If Error Then Exit Sub
Do
If FilaFinal < HojaPresupuesto.UsedRange.Rows.Count Then
FilaFinal = FilaFinal + 1
Else
Error = True
Exit Do
End If
Loop While HojaPresupuesto.Cells(FilaFinal, 2) <> "Total"
If Error Then Exit Sub
For i = FilaFinal To HojaPresupuesto.UsedRange.Rows.Count
If Left(HojaPresupuesto.Cells(i, 2), 7) = "Resumen" Then
If HojaPresupuesto.Cells(i, 5).Formula = "=A" & FilaInicial & "" Then
HojaPresupuesto.Rows(i).Delete
Exit For
End If
End If
Next i
Do
FilaFinal = FilaFinal + 1
Loop While HojaPresupuesto.Cells(FilaFinal, 2) = ""
FilaFinal = FilaFinal - 1
HojaPresupuesto.Rows(FilaInicial & ":" & FilaFinal).EntireRow.Delete
HojaPresupuesto.Cells(FilaInicial, Columna).Select
End Sub
' Insertar las filas correspondientes a las celdas seleccionadas
Sub InsertarFilas()
Dim fila, Columna As Long
fila = Selection.Row
Columna = Selection.Column
If HojaPresupuesto.Cells(fila - 1, 2) = "Producto" Then
Selection.EntireRow.Insert
HojaPresupuesto.Rows(fila - 1).Copy
Selection.EntireRow.PasteSpecial
Application.CutCopyMode = False
HojaPresupuesto.Cells(fila, Columna).Select
End If
End Sub
' Inserta el apartado correspondientes a las celdas seleccionadas
Sub InsertarApartados()
Dim fila, Columna As Long
Dim FilaInicial, FilaFinal As Long
Dim Error As Boolean
Dim i As Long
Error = False
fila = Selection.Row
Columna = Selection.Column
FilaInicial = fila
FilaFinal = fila
Do
If FilaInicial > 1 And HojaPresupuesto.Cells(FilaInicial, 2) <> "Total" Then
FilaInicial = FilaInicial - 1
Else
Error = True
Exit Do
End If
Loop While HojaPresupuesto.Cells(FilaInicial, 2) <> "Título"
If Error Then Exit Sub
Do
If FilaFinal < HojaPresupuesto.UsedRange.Rows.Count Then
FilaFinal = FilaFinal + 1
Else
Error = True
Exit Do
End If
Loop While HojaPresupuesto.Cells(FilaFinal, 2) <> "Total"
If Error Then Exit Sub
Do
FilaFinal = FilaFinal + 1
Loop While HojaPresupuesto.Cells(FilaFinal, 2) = ""
FilaFinal = FilaFinal - 1
HojaPresupuesto.Rows(FilaInicial & ":" & FilaFinal).EntireRow.Insert
HojaPresupuesto.Rows(FilaFinal + 1 & ":" & 2 * FilaFinal - FilaInicial + 1).EntireRow.Copy
HojaPresupuesto.Rows(FilaInicial & ":" & FilaFinal).EntireRow.PasteSpecial
' Dim resumen As Boolean
For i = FilaFinal To HojaPresupuesto.UsedRange.Rows.Count
If HojaPresupuesto.Cells(i, 2) = "Resumen título" Then
Exit For
End If
Next i
Dim Prueba As String
Prueba = "=A" & FilaFinal + 1 & ""
Do Until HojaPresupuesto.Cells(i, 5).Formula = Prueba
i = i + 1
Loop
' i = i + 1
With HojaPresupuesto