Home > Enterprise >  How to delete non-contiguous areas of a sheet
How to delete non-contiguous areas of a sheet

Time:06-26

I'm trying to delete several area of a sheet which are non-contiguous, I used the union method to select them, and they do get selected on the sheet, but I get a message: Delete method of Range class failed.

Range("A4").Select
lrow = Range("A" & Rows.Count).End(xlUp).Row
lCol = Cells(6, Columns.Count).End(xlToLeft).Column



Union(Range("A4:D" & lrow), Range("H4:J" & lrow), Range("N4:N" & lrow), Range("P4:T" & lrow)).Select
'Range("H4:H500,I4:I500,J4:J500,N4:N500,").Select
Selection.Delete Shift:=xlLeft

Any idea what I'm doing wrong? thank you

CodePudding user response:

Use Shift:=xlToLeft instead of Shift:=xlLeft. When in doubt record a macro and review the code for hints to the issue.

With Range("A4:P4", Range("A" & Rows.Count).End(xlUp))
    Union(.Columns("A"), .Columns("H"), .Columns("N"), .Columns("P")).Delete Shift:=xlToLeft
End With
  • Related