excel - VBA error 'Cannot change part of a merged cell' -


having problem vba error "cannot change part of merged cell"

here code. clears range on first sheet, hides raw samples sheet. loop clears ranges on unhidden sheets in workbook because formatted exact same. code works if go sheets , clear formatting merged cells. need code run on number of workbooks having time consuming or i'd have add code clear users formats before clearing ranges.

sheets("raw samples").select range("a9:ab3000").select selection.clearcontents activewindow.selectedsheets.visible = false  dim ws worksheet each ws in activeworkbook.worksheets ws.range("b3:g342").clearcontents next ws  activeworkbook.sheets("raw samples").visible = true 

my questions are

  1. does next loop still check formatting on hidden sheet?
  2. is there way around having unformat sheet still clear specified ranges?

q1. next loop still check formatting on hidden sheet?

no doesn't

q2. there way around having unformat sheet still clear specified ranges?

yes. trying?

sub sample()     dim ws worksheet     dim rng range     dim boolhidden boolean      each ws in activeworkbook.worksheets         if ws.name <> "raw samples"             set rng = ws.range("b3:g342")              if ws.visible = false                 boolhidden = true                 ws.visible = true             end if              application.goto reference:=rng             selection.clearcontents              if boolhidden = true                 ws.visible = false                 boolhidden = false             end if         end if     next ws end sub 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -