Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear Contents of a Column

Tags:

excel

vba

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).

Thanks for the help.

like image 214
icobes Avatar asked Oct 05 '11 00:10

icobes


People also ask

How do I clear contents of a column in Excel VBA?

In VBA, there is a method called ClearContents that you can use to clear values and formulas from a cell, range of cells, and the entire worksheet. To use this method, first, you need to define the expression somewhere you want to clear the content, and then type “. ClearContents”.


2 Answers

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.

like image 118
Banjoe Avatar answered Oct 04 '22 22:10

Banjoe


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.

like image 29
aevanko Avatar answered Oct 04 '22 21:10

aevanko