Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

' Seleccionar las celdas K5:N5 y a partir de ahí insertar 200 filas en la tabla dinámica

Range("K5:N5").Select

Selection.Resize(200).EntireRow.Insert

' Copiar la columna E desde la fila 3 y pegarla en la columna K a partir de la fila 5 como valores

Range("E3").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.Copy

Range("K5").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False,


Transpose:=False

' Copiar la columna B desde la fila 3 y pegarla en la columna L a partir de la fila 5 como valores

Range("B3").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.Copy

Range("L5").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False,


Transpose:=False

' Copiar la columna H desde la fila 3 y pegarla en la columna M a partir de la fila 5 como valores

Range("H3").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.Copy

Range("M5").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False,


Transpose:=False

' Eliminar las filas vacías o que contengan espacios en la columna M de la tabla dinámica

Dim tbl As PivotTable


Set tbl = ActiveSheet.PivotTables(1)

Dim i As Long

For i = tbl.TableRange2.row To tbl.TableRange2.Rows.Count + tbl.TableRange2.row - 1

If Len(Trim(CStr(Range("M" & i).Value))) = 0 Then

tbl.PivotSelect "'Row Labels'[" & i - tbl.TableRange2.row + 1 & "]", xlDataAndLabel, True

tbl.PivotFields(tbl.DataFields(1).Name).ClearAllFilters

tbl.PivotFields(tbl.DataFields(1).Name).CurrentPage = ""

tbl.PivotFields(tbl.DataFields(1).Name).PivotItems(1).Visible = False

End If

Next i

' Colocar el cursor en la celda A1

Range("A1").Select

'
Sub Guardar()

'

' Guardar Macro

'

'

Range("K5:N5").Select

Selection.ListObject.ListRows.Add (1)

Sheets("Utilidades").Select

Range("E3").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.Copy

Range("K5").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("E3").Select

Range(Selection, Selection.End(xlDown)).Select

Application.CutCopyMode = False

Selection.Copy

Range("K5").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("B3").Select

Range(Selection, Selection.End(xlDown)).Select

Application.CutCopyMode = False

Selection.Copy

Range("L5").Select
ActiveSheet.Paste

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("H3").Select

Range(Selection, Selection.End(xlDown)).Select

Application.CutCopyMode = False

Selection.Copy

Range("M5").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

ActiveSheet.ListObjects("Tabla7").Range.AutoFilter Field:=3, Criteria1:="="

Application.CutCopyMode = False

Selection.ClearContents

Selection.ClearContents

Selection.ClearContents

ActiveSheet.ListObjects("Tabla7").Range.AutoFilter Field:=3

Selection.SpecialCells(xlCellTypeBlanks).Select

Selection.ListObject.ListRows(1).Delete

Selection.ListObject.ListRows(1).Delete

Selection.ListObject.ListRows(1).Delete

Selection.ListObject.ListRows(1).Delete

Selection.ListObject.ListRows(1).Delete

Selection.ListObject.ListRows(1).Delete

Selection.ListObject.ListRows(1).Delete

Selection.ListObject.ListRows(1).Delete

Selection.ListObject.ListRows(1).Delete

Selection.ListObject.ListRows(1).Delete

Range("B2").Select

End Sub
tbl.ListRows.Add Range("K5").Row, 200

You might also like