vba 清除列的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7655393/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:00:41  来源:igfitidea点击:

Clear Contents of a Column

excelvbaexcel-vba

提问by icobes

How would I clear the contents of a column from cell A3 to cell __ where __ represents the last entry in the column (assuming there are no empty spaces between entries).

我将如何清除从单元格 A3 到单元格 __ 的列的内容,其中 __ 表示列中的最后一个条目(假设条目之间没有空格)。

Thanks for the help.

谢谢您的帮助。

回答by Banjoe

range("A3", columns("A").SpecialCells(xlCellTypeLastCell)).Delete

That will delete A3 through the last cell in column A, regardless of any blanks in the column.

这将通过 A 列中的最后一个单元格删除 A3,无论该列中是否有任何空格。

range("A3", range("A3").End(xlDown)).Delete

That will delete from A3 down to the first blank cell after A3 in column A.

这将从 A3 删除到 A 列中 A3 之后的第一个空白单元格。

回答by aevanko

Range("A3", Range("A3").End(xlDown)).Clear

Using .Delete will actually delete the cells, shifting up any cells that might appear after this list (separated by a blank cell). If you just want to clear the contents, .Clear is a good way to go.

使用 .Delete 将实际删除单元格,将可能出现在此列表之后的任何单元格向上移动(由空白单元格分隔)。如果你只是想清除内容, .Clear 是一个不错的方法。

回答by kodi1911

I would use a vbNullString, because it's slightly faster and works efficently on huge amount of data worksheets.

我会使用 vbNullString,因为它稍微快一点,并且可以有效地处理大量数据工作表。

Paste 'nothing' from A3 to the first blank cell in column A:

将 A3 中的“无”粘贴到 A 列中的第一个空白单元格:

Range(Cells(1,3), Cells(Range("A3").End(xlDown).Row,1)).Value = vbNullString

Paste 'nothing' from A3 to the last cell in column A:

将 A3 中的“无”粘贴到 A 列的最后一个单元格:

Range(Cells(1,3), Cells(Range("A3").SpecialCells(xlTypeLastCell),1)).Value = vbNullString

回答by Michael Easterbrook

I have had good results with this:

我在这方面取得了不错的成绩:

Set tbl = ActiveSheet.ListObjects("Table_Name")
Count = tbl.DataBodyRange.Rows.Count

Range("AC2:AC" + CStr(Count)).Select
Selection.ClearContents