This will delete Col B, D, F etc onwards to the end of your data. If you want
A, C, E etc to go, then change the 2 to a 1 in teh line For x = 2 To lc (to
For x = 1 To lc)
Sub DelCols()
Dim LastCol As Integer
Dim lc As Integer
Dim x As Integer
Public Sub DelEveryOtherColumn()
Dim result As Integer
Dim cell As Range
Dim delRange As Range
Dim i As Integer
Dim refStr1 As String
Dim refStr2 As String
If Application.ReferenceStyle = xlR1C1 Then
refStr1 = "1"
refStr2 = "2"
Else
refStr1 = "A"
refStr2 = "B"
End If
result = MsgBox(prompt:="Start with Column " & _
refStr1 & "?" & vbNewLine & vbNewLine & _
"Click ""Yes"" for " & refStr1 & ", ""No"" for " & _
refStr2, Title:="Delete Alternate Columns", _
Buttons:=vbYesNoCancel)
If result = vbCancel Then Exit Sub
Set delRange = Cells(1, 2 + (result = vbYes))
For i = delRange.Column + 2 To _
Cells.SpecialCells(xlCellTypeLastCell).Column Step 2
Set delRange = Union(delRange, Cells(1, i))
Next i
delRange.EntireColumn.Delete
ActiveSheet.UsedRange
End Sub
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.