Search code examples
vbaexceldelete-row

Delete 2 Rows and 2 Columns in VBA


My code is below. I want to delete Rows 81 and 82 and columns F and H. My code below successfully deletes the rows but fails to delete the 2 columns. This with block is within a larger Sub.

With Sheets("PDEL_Report 500K")
    Rows("81:82").Select
    Selection.ClearContents
    Selection.Delete Shift:=xlUp

    Columns("F:F,H:H").Select
    Selection.ClearContents
    Selection.EntireColumn.Delete Shift:=xlLeft

End With

Solution

  • With Sheets("PDEL_Report 500K")
        .Rows("81:82").EntireRow.Delete Shift:=xlUp
        .Columns("H:H").EntireColumn.Delete Shift:=xlLeft 'delete H first so shift does not affect current column F
        .Columns("F:F").EntireColumn.Delete Shift:=xlLeft
    End With