excel - Range SpecialCells ClearContents clears whole sheet instead -


i have sheet in excel 2010 setup pseudo form (i didn't create it, i'm trying fix it) formatting suggests user can enter in cells. depending on functionality these areas need reset, i.e. cleared although formulae , standard/conditional formatting need kept. have defined each of these cells/ranges named ranges can loop through them using following code: -

public sub resetdetailsheet()     dim nm name      thisworkbook         each nm in .names             if left(nm.name, 9) = "nmrdetail"                 range(nm.name).specialcells(xlcelltypeconstants).clearcontents             end if         next     end end sub 

for reason instead of clearing constants specific range clearing constants entire sheet losing titles/headings. formulae , standard/conditional formatting staying expected.

what doing wrong?!?!

as test using immediate window tried clearing specific cell, e.g.

range("g7").specialcells(xlcelltypeconstants).clearcontents 

but still cleared constants entire sheet.

what missing? don't understand. maybe i'm being dumb. sorry, can't upload example. place pretty locked down.

range({any single cell}).specialcells({whatever}) seems work off entire sheet.

range({more 1 cell}).specialcells({whatever}) seems work off specified cells.

so, make sure range has more single cell before clear - if range single cell, check if .hasformula; if that's case .value isn't constant:

with thisworkbook     each nm in .names         if left(nm.name, 9) = "nmrdetail"             if nm.referstorange.count > 1                 nm.referstorange.specialcells(xlcelltypeconstants).clearcontents             elseif not nm.referstorange.hasformula                 nm.referstorange.clearcontents             end if         end if     next end 

note i'm using name.referstorange instead of fetching range name off active sheet.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -