VBA code to delete cell contents

  • Thread starter Thread starter Robert Crandal
  • Start date Start date
R

Robert Crandal

How does everybody write code to delete the contents of
a cell, such as cell "A1"???

I normally use the following code:

Range("A1").Value = ""

Is that correct?? I get the feeling that I am setting cell "A1"
to an empty string, rather than actually deleting the current
contents.
 
Hi Robert

Your method works. Here is another method which gets the job done as
well.

Range("A1").ClearContents

Take care

Marcus
 
Hi

When I delete the contents of a single cell, I usually use .Value="" as you
do, but when I want to delete contents multiple cells, I use .ClearContents
which delete the content of the cells.

Using .Clear will not only delete the content but also clear any formating
in the cell(s).

Regards,
Per
 
For Excel VBA you can try the clearcontents method for a Range

Range("A1").ClearContents

Range("A1")="" does the same as Range("A1") = vbNullString

When you mention Range("A1")="" the computer generate a null string....and
then assign that value to the cell; whereas vbNullString is a null string and
so should be quicker.


If this post helps click Yes
 
..Value = "" works on multiple cells as well..

Per Jessen said:
Hi

When I delete the contents of a single cell, I usually use .Value="" as you
do, but when I want to delete contents multiple cells, I use .ClearContents
which delete the content of the cells.

Using .Clear will not only delete the content but also clear any formating
in the cell(s).

Regards,
Per



.
 
I know that .Value="" work on multiple cells, but i prefer to use
..ClearContents when working with multiple cells.
 
Back
Top