如何删除范围 Excel VBA 的列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3592273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete columns of a range Excel VBA
提问by guest1
I have a range named "Start" located at cell "I21". And I have another range named "End" located at cell "Q21". I want to write a code to delete all the columns between them. In other words, I want to delete columns J,K,L,M,N,O,P completely. Here is the code I have:
我有一个名为“开始”的范围位于单元格“I21”。我在单元格“Q21”中有另一个名为“End”的范围。我想编写一个代码来删除它们之间的所有列。换句话说,我想完全删除列 J、K、L、M、N、O、P。这是我的代码:
with ThisWorkbook.sheets("Sheet1")
'unprotect sheet
.Columns(.Range("Start").Column+1 & ":" & .Range("End").Column-1).Select
Selection.Delete Shift:xlLeft
End with
when it comes to the first line .Columns... it gives me an error as undefined application. please help,
当涉及到第一行 .Columns... 它给我一个未定义应用程序的错误。请帮忙,
回答by shahkalpesh
Range(Range("start").Offset(,1), Range("end").Offset(,-1)).EntireColumn.Delete
回答by Fandango68
You don't have to specify a row reference...
您不必指定行引用...
ActiveSheet.Range(, MyColumn).EntireColumn.Delete
Where 'myColumn'is an arbitrary reference to a column number or anything you want.
'myColumn'对列号或您想要的任何内容的任意引用在哪里。
回答by user1448329
Dim xlsRange As Excel.Range
xlsRange = xlsSheet.Range("i2", "i10")
xlsRange.EntireColumn.Delete()

