6

Just wanted to share as I had huge amount of trouble looking for ways to do this online and have finally gotten it through series of trial and error.

Sheet1.Range(Cells(1, 11), Cells(1, 100)).EntireColumn.Delete

This deletes columns 11 to 100.

5
  • Columns/Rows A11 - A100 you mean Commented Sep 18, 2013 at 17:07
  • @ScottFiander - take another look... Commented Sep 18, 2013 at 17:09
  • 2
    Note - this will fail if Sheet1 isn't the active sheet. Sheet1.Range(Sheet1.Cells(1, 11), Sheet1.Cells(1, 100)) Commented Sep 18, 2013 at 17:10
  • Oh yes Tim sorry I edited my code on my end but not here. Commented Sep 18, 2013 at 18:59
  • And where do you type this in excel? @Jay Commented Sep 1, 2017 at 16:44

2 Answers 2

9
With Sheet1
    .Range(.Cells(1, 11), .Cells(1, 100)).EntireColumn.Delete
End With
Sign up to request clarification or add additional context in comments.

Comments

8

More ways

Deleting consecutive columns like 1 - 100

Sub Sample()
    With Sheet1
        'A:CV
        .Columns(ReturnName(1) & ":" & ReturnName(100)).Delete Shift:=xlToLeft
    End With
End Sub

'~~> Returns Column Name from Col No
Function ReturnName(ByVal num As Integer) As String
    ReturnName = Split(Cells(, num).Address, "$")(1)
End Function

Deleting non consecutive columns like 1, 3, 5

Sub Sample()
    With Sheet1
        'A:A,C:C,E:E
        .Range( _
                ReturnName(1) & ":" & ReturnName(1) & "," & _
                ReturnName(3) & ":" & ReturnName(3) & "," & _
                ReturnName(5) & ":" & ReturnName(5) _
               ).Delete Shift:=xlToLeft
    End With
End Sub

Function ReturnName(ByVal num As Integer) As String
    ReturnName = Split(Cells(, num).Address, "$")(1)
End Function

'**Another way**

Sub Sample()
    Dim Rng As Range

    With Sheet1
        Set Rng = Union(.Columns(1), .Columns(3), .Columns(5))
    End With

    Rng.Delete Shift:=xlToLeft
End Sub

1 Comment

Thanks Sid, although I might just use the one I have posted since it's one-liner and easier for me to understand. For doing this with multiple non-consecutive columns, Union() look's great and I will start using that as I have not heard of this until today :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.