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!
 
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

Thanks so much :) works perfectly

I can't see any difference between the way excel executes my code and yours but it feels like yours is faster.
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Yours would look at rows 7:65536 (assuming you're pre XL07 given you're using rows.count) whereas the above would only go to the last used cell -- so if that's on row 15000 it will only use range 7:15000

EDIT: for clarification: xllastcell does not refer to say IV65536 (pre XL07) but to the last "used" cell on the sheet.
 
Last edited:
Upvote 0
Yours would look at rows 7:65536 (assuming you're pre XL07 given you're using rows.count) whereas the above would only go to the last used cell -- so if that's on row 15000 it will only use range 7:15000

EDIT: for clarification: xllastcell does not refer to say IV65536 (pre XL07) but to the last "used" cell on the sheet.

Yep, that's perfect! I was looking for things that check for the last used cell or range, but couldn't express it.

So now I do know that rows.count does look at all the rows whereas xlastcell is just the last used cell.

I have virtually no knowledge of VBA, just learning by doing :) all of your explanations are just what I need!

Again, Tks a lot!
 
Upvote 0

Forum statistics

Threads
1,215,746
Messages
6,126,647
Members
449,325
Latest member
Hardey6ix

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