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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

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
 

Forum statistics

Threads
1,172,067
Messages
5,878,982
Members
433,388
Latest member
nana2525

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