只是想分享一下,因为我在寻找在线执行此操作的方法时遇到了很多麻烦,最终通过一系列的反复试验得到了它。
Sheet1.Range(单元格(1, 11), 单元格(1, 100)).EntireColumn.Delete
这将删除第 11 到 100 列。
更多方式
删除连续的列,如 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
删除非连续列,如 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
With Sheet1
.Range(.Cells(1, 11), .Cells(1, 100)).EntireColumn.Delete
End With