Clear non-blank cells?

Hai

New Member
Joined
Jun 24, 2008
Messages
15
Hi all,

Please advise on the best script to clear all non-blank cells, in my case from Cells(7,1) forward. I currently use this:

.Range(Cells(7, Columns.Count), Cells(Rows.Count, 1)).Value = ""

Will this scipt take a lot of memory to execute? Is there any other method?

Tks a lot!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,124
presumably you want:

Code:
Rows("7:65536").ClearContents

you could even try deleting the rows (8:65536) as the rows would simply be replaced (but turn off displayalerts before delete and reset to true after delete), obviously you would lose formatting if that's an issue.

If you are using XL07 the 65536 may need to be more flexible... ;)
 
Last edited:
Upvote 0

Makrini

Well-known Member
Joined
May 22, 2007
Messages
1,035
or another way..

Range("A1", Range("A1").End(xlToRight).End(xlDown)).ClearContents
 
Upvote 0

Hai

New Member
Joined
Jun 24, 2008
Messages
15
presumably you want:

Code:
Rows("7:65536").ClearContents

you could even try deleting the rows (8:65536) as the rows would simply be replaced (but turn off displayalerts before delete and reset to true after delete), obviously you would lose formatting if that's an issue.

If you are using XL07 the 65536 may need to be more flexible... ;)

Thanks for the command. Still, defining 7:65536 will enlarge the file to a few MBs.

And .Clear or .ClearContents will take away formatting as well right? I need to keep the formatting.
 
Upvote 0

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,124
.ClearContents will not clear formatting whereas a straightforward .Clear would as would deleting the rows altogether (obviously)
 
Upvote 0

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,124
Yes BUT risky -- if you have any blanks between say row 7 and the last row of data it's possible it won't work -- ie if row 9 is blank and rows 7,8,10 are not it will clear only rows 7 & 8.

you could try the below to limit amount of cells selected

Code:
Range(Cells(7, 1), Cells(7, 1).SpecialCells(xlLastCell)).ClearContents
 
Last edited:
Upvote 0

Forum statistics

Threads
1,191,189
Messages
5,985,198
Members
439,947
Latest member
fabiannic

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