excel vba - Why is this macro copying multiple times? -



excel vba - Why is this macro copying multiple times? -

i found macro , need whenever it's activated seems copy/paste info multiple times. master list should have 75 or lines , when runs ends @ 268. why doing that? also, there way edit if sheet has no info in after "a1" doesn't re-create sheet?

option explicit private sub worksheet_activate() 'merge sheets in workbook 1 summary sheet (stacked) dim cs worksheet, ws worksheet, lr long, nr long application.screenupdating = false set cs = sheets("master list") cs.activate range("a2:f" & rows.count).clearcontents each ws in worksheets if ws.name <> "master list" nr = cs.range("a" & rows.count).end(xlup).row + 1 lr = ws.range("a" & rows.count).end(xlup).row ws.range("a2:f" & lr).copy cs.range("a" & nr) end if next ws application.screenupdating = true end sub

you have in private sub worksheet_activate() event of workbook. if written "master list" sheet's code, activating sheet line cs.activate trigger macro again... 1 running. it's hard why creates 268 , not infinite, or double... it's tough , may dependant on speed @ excel works , it's single threadiness or other deep downwards dark mystery of excel , vba.

instead of

cs.activate range("a2:f" & rows.count).clearcontents

try

cs.range("a2.f" & rows.count).clearcontents

if find writing .activate or .select in vba code, doing not-so-great.

excel-vba

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -