开发者

Clear Contents of a Column

开发者 https://www.devze.com 2023-04-10 23:32 出处:网络
How would I clear the contents of a column from cell A3 to cell __ where __ represents the last entry i开发者_如何学JAVAn the column (assuming there are no empty spaces between entries).

How would I clear the contents of a column from cell A3 to cell __ where __ represents the last entry i开发者_如何学JAVAn the column (assuming there are no empty spaces between entries).

Thanks for the help.


range("A3", Range("A" & Columns("A").SpecialCells(xlCellTypeLastCell).Row)).Delete

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

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

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

EDIT: Fixed the first code snippet so it only deletes cells in column A.


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.


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

Paste 'nothing' from A3 to the first blank cell in column 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:

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号