delete alternate column

  • Thread starter Thread starter mary
  • Start date Start date
Hi Mary

This will delete every second column in your sheet. Take care

marcus

Sub RemCol()

Dim Col As Integer
Col = 2
Application.ScreenUpdating = False
For i = Col To 256 Step 2
Cells(1, Col).EntireColumn.Delete
Next i

End Sub
 
I think that Marcus' code will delete all columns except column 1. You need
to work backwards when deleting columns or rows.

Try this modification

Sub RemCol()

Dim Col As Integer
Col = 2
Application.ScreenUpdating = False
For i = 256 To Col Step -2
Cells(1, i).EntireColumn.Delete
Next i

End Sub
 
one way

Sub test()
Dim lastcol As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
lastcol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
For i = lastcol To 1 Step -1
If i Mod 2 = 0 Then
Columns(i).Delete
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top