ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   delete alternate column (https://www.excelbanter.com/excel-programming/414579-delete-alternate-column.html)

Mary

delete alternate column
 
How can I delete every other column (B, D, F.....) in Excel?

marcus[_3_]

delete alternate column
 
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

OssieMac

delete alternate column
 
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

--
Regards,

OssieMac


"marcus" wrote:

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


Gary Keramidas

delete alternate column
 
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


--


Gary


"mary" wrote in message
...
How can I delete every other column (B, D, F.....) in Excel?





All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com