VBA code to delete cell contents

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

marcus

Hi Robert

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

Range("A1").ClearContents

Take care

Marcus
 
P

Per Jessen

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
 
J

Jacob Skaria

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
 
J

Jacob Skaria

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



.
 
P

Per Jessen

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top