VBA delete entire columns

phil133

Active Member
Joined
May 5, 2015
Messages
257
Office Version
  1. 365
Platform
  1. Windows
Hi. VBA newbie here. In this code after running some macros I want to delete some columns (A, D to F and H to L). Unortunately it doesn't do that.



Code:
Sheets("P_L events up to 2 months").Select
    Range("B5:D424").Select
    Selection.ClearContents
    Range("B5").Select
    Application.Run "'RSX NEW.xlsm'!copy_paste1"
    Sheets("Sheet1").Select
    Application.Run "'RSX NEW.xlsm'!copy_last_row1"
    Columns("A:A").Select
    Selection.Delete
    Columns("D:F").Select
    Selection.Delete
    Columns("H:L").Select
    Selection.Delete
End Sub
Thanks for any help!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Consider this: If you delete column A, then column B shifts left to be the new column A. Then if you delete columns D:F, you are actually deleting what use to be columns E:G because they have shifted left as well because of the previous delete.

Consider deleting columns from right to left.

Alternatively, you could delete noncontinuous columns like this.
Code:
Range("A:A,D:F,H:L").Delete
 
Upvote 0

Forum statistics

Threads
1,203,620
Messages
6,056,334
Members
444,861
Latest member
B4you_Andrea

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