Delete Non-Contiguous Columns Issue

03856me

Active Member
Joined
Apr 4, 2008
Messages
297
After research I have come up with this code to dump my data to another file and save it, then clear the information and formatting that is not needed. However, the row identified below with '<===== errors out ever time with the error: Delete method of Range class failed

Your help is greatly apprecaited ---

Code:
Sub ProcessNewFile()
    Application.ScreenUpdating = False
 
    Worksheets("data").Select
    ActiveSheet.Cells.EntireColumn.Hidden = False
    ActiveSheet.Cells.EntireRow.Hidden = False
 
    Range("R:R,T:T,V:V,X:X,Z:Z,AB:KN").Delete      '<=====
 
    ActiveSheet.Shapes("ReportMenu").Delete
 
    Worksheets("Hold").Select
    ActiveSheet.Shapes("Rounded Rectangle 1").Delete
    Range("I:J").Delete
    Range("B9").Validation.Delete
    Range("A1:AC166").Interior.ColorIndex = xlColorIndexNone
 
ActiveWorkbook.Save
ActiveWorkbook.Close
Worksheets("data").Visible = False
Worksheets("Hold").Visible = False
MsgBox "YOUR NEW REPORT HAS BEEN SAVED"
Application.ScreenUpdating = True
End Sub
 
Figured this out. Here is the code in case somone else needs it. I could not get the delete to work properly if all in one statement, but when I broke it up to individual lines it worked just fine.

Code:
Sub ProcessNewFile()
    Application.ScreenUpdating = False
 
    Worksheets("data").Select
    ActiveSheet.Cells.EntireColumn.Hidden = False
    ActiveSheet.Cells.EntireRow.Hidden = False
 
[COLOR=seagreen]'   Range("R:R,T:T,V:V,X:X,Z:Z,AB:KN").Delete  THIS DID NOT WORK[/COLOR]
[COLOR=seagreen]'   Delete in reverse order because columns change[/COLOR]
 
    Range("AB:KN").Delete
    Range("Z:Z").Delete
    Range("X:X").Delete
    Range("V:V").Delete
    Range("T:T").Delete
    Range("R:R").Delete
 
ActiveWorkbook.Save
ActiveWorkbook.Close
 
MsgBox "YOUR NEW REPORT HAS BEEN SAVED"
 
Application.ScreenUpdating = True
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top