VBA - Delete Columns Excel 2010

shemayisroel

Well-known Member
Joined
Sep 11, 2008
Messages
1,867
Hi,


My data range starts from C1:DH3.

I need some code that starting from D1 deletes 7 columns, misses a column then keeps on deleting 7 columns misses a column etc up until Column DH.

Using the example above, the first couple of deletes will delete columns D-J keep column K, delete columns L-R keep S etc

Thanks
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Does this do what you want?
Code:
Sub Delete7ColumnsKeep1()
  Dim X As Long
  For X = 4 To 112 Step 8
    Columns(X).Resize(, 7).Delete
  Next
End Sub
 
Upvote 0
Sorry, I rushed that code out just a little too fast.:eeek: Try this instead...
Code:
Sub Delete7ColumnsKeep1()
  Dim X As Long, LastCol As String
  LastCol = "DH"
  Application.ScreenUpdating = False
  For X = 8 * Int(Cells(1, LastCol).Column / 8) - 4 To 4 Step -8
    Columns(X).Resize(, 7).Delete
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Sorry, I rushed that code out just a little too fast.:eeek: Try this instead...
Code:
Sub Delete7ColumnsKeep1()
  Dim X As Long, LastCol As String
  LastCol = "DH"
  Application.ScreenUpdating = False
  For X = 8 * Int(Cells(1, LastCol).Column / 8) - 4 To 4 Step -8
    Columns(X).Resize(, 7).Delete
  Next
  Application.ScreenUpdating = True
End Sub

Tested with a small sample range and it works - thank you so kindly!:)
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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