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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

ChrisUK

Well-known Member
Joined
Sep 3, 2002
Messages
675
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
 

Emily

Active Member
Joined
Aug 28, 2002
Messages
304
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,119
Messages
5,857,487
Members
431,882
Latest member
saaaaaaaaaaaaaaaaaaaaaa

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
Top