ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to zero out non-contiguous ranges (https://www.excelbanter.com/excel-programming/398160-re-how-zero-out-non-contiguous-ranges.html)

Tom Ogilvy

How to zero out non-contiguous ranges
 
for each cell in Range("A2:A35")
if cell.locked = False then
cell.clearcontents
end if
Next

--
Regards,
Tom Ogilvy


"Dean" wrote:

I have a range name which involves about four non-contiguous blocks of
contiguous cells (say, cells a2 to a4, then a7 to a12, then a15 to a18, then
a30 to a35, right now, though I might later insert some rows in the middle,
so the range name's cells would adjust). I would like to just set all cells
in these blocks to zero with a macro in the easiest way possible. Actually,
easier yet, would be to set the whole range to zero from cells a2 to a35,
but have it skip any cells whose format is protected, whether or not
protection is actually on.

Can someone give me the code to do that?

Thanks!
Dean





All times are GMT +1. The time now is 09:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com