Any difference between .value="" and .clearcontents

Emily

Active Member
Joined
Aug 28, 2002
Messages
304
Is there any difference between .value="" and .clearcontents? Which one is better to clear the cells contents?

Thanks
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I've run a couple of tests and was surprised at the results.

1. Blank sheet with just the following VBA code saved was 15.5K

Sub clear()
Set rng = Range("a1:a1000")
For Each c In rng
c.Value = ""
Next
End Sub

2. Ran the code and saved the sheet, now 19K.

3. changed the code so the c.value line now reads c.clearcontents, ran this saved the sheet - result 19K!

It seems Excel is similar to Access in this way, removing a value does not free space and you'd need to compact it somehow.

My prefference would always be to clearcontents as I would have thought it would remove any references to cells from the file. Maybe this will be corrected in a later version of Excel (I'm running 2000)

Hope this helps a bit
 
Upvote 0
Thanks. I found the difference using IsEmpty Function.

Sub test()
Dim MyVar, MyCheck
MyCheck = IsEmpty(MyVar) ' Return True
MyVar = Cells(1, 1) ' Cells(1, 1) = ""
MyCheck = IsEmpty(MyVar) ' Return False
Cells(1, 2).ClearContents
MyVar = Cells(1, 2)
MyCheck = IsEmpty(MyVar) ' Return True
End Sub
 
Upvote 0

Forum statistics

Threads
1,218,662
Messages
6,143,757
Members
450,502
Latest member
sakaria_123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top