ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA code to delete cell contents (https://www.excelbanter.com/excel-programming/436796-vba-code-delete-cell-contents.html)

Robert Crandal

VBA code to delete cell contents
 
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.



marcus[_3_]

VBA code to delete cell contents
 
Hi Robert

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

Range("A1").ClearContents

Take care

Marcus

Per Jessen

VBA code to delete cell contents
 
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

"Robert Crandal" skrev i meddelelsen
...
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.




Jacob Skaria

VBA code to delete cell contents
 
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
---------------
Jacob Skaria


"Robert Crandal" wrote:

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.


.


Jacob Skaria

VBA code to delete cell contents
 
..Value = "" works on multiple cells as well..

"Per Jessen" wrote:

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

"Robert Crandal" skrev i meddelelsen
...
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.



.


Per Jessen

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

"Jacob Skaria" skrev i meddelelsen
...
.Value = "" works on multiple cells as well..

"Per Jessen" wrote:

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

"Robert Crandal" skrev i meddelelsen
...
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.



.




All times are GMT +1. The time now is 01:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com