excel - VBA paste method -



excel - VBA paste method -

i've been working on learning ways improve code , taking examples site , others -- can't seem past runtime error 1004 "paste method of worksheet class failed". have 2 other similar macros , button run 3. runs first 2 same syntax around pasting "myqueue" file fine, 3rd not paste , throws error. can help?

sub csqagentsummaryedit() dim mypath string mypath = " path " myfile = " file " queuepath = "path " myqueue = " file " dim wb1 workbook dim wb2 workbook set wb1 = workbooks.open(queuepath) set wb2 = workbooks.open(mypath) columns("a:v").delete shift:=xlup columns("b").delete shift:=xlup columns("c:r").delete shift:=xlup range("a1").select selection.end(xldown).select activecell.offset(2, 0).range("a1").select selection.consolidate sources:= _ "'file info " _ , function:=xlsum, leftcolumn:=true range("a1").currentregion.delete shift:=xlup rows("1:1").delete range("a1").currentregion.select selection.borders .linestyle = xlcontinuous .weight = xlthin .colorindex = xlautomatic end selection.copy workbooks.open (queuepath) range("a1").select selection.end(xldown).select activecell.offset(20, 0).range("a1").select activesheet.paste , false workbooks(myqueue).save workbooks(myfile).close false end sub

you seem opening queuepath workbook twice.

instead of

selection.copy workbooks.open (queuepath) range("a1").select

try

selection.copy wb2.sheets("sheet1").range("a1").select

specifying workbook using help avoid pasting wrong workbook/pasting errors.

excel vba

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -