excel - Error 1004: PasteSpecial method of range class failed -


i having little bit trouble, want copy 1 column workbooks 1 new workbook , transpose it, i've got error : error 1004: pastespecial method of range class failed

private sub commandbutton1_click()      activesheet.range("c2:c30").copy     workbooks.open filename:="e:\pendidikan_bjn\sum.xlsx"     ecolumn = activesheet.cells(1, columns.count).end(xltoleft).column     if ecolumn >= 1 ecolumn = ecolumn + 1     activesheet.cells(1, ecolumn).select     selection.pastespecial paste:=xlpasteall, operation:=xlnone, skipblanks:=false, transpose:=true     activeworkbook.save     activeworkbook.close     application.cutcopymode = false  end sub 

reason of issue

you trying copy cell c2 c30, 29 cells (30-2+1) other workbook transposing them. in other words paste these cells single row 29 columns.

in other workbook select "dynamically" columns if ecolumn >= 1 ecolumn = ecolumn + 1 , not have selection of 29 columns required paste.

the result in end error message error 1004: pastespecial method of range class failed.

solution

one of solutions select directly right number of columns paste data , this:

private sub commandbutton1_click()      activesheet.range("c2:c30").copy     ' store number of rows selected in ecolumn associated before opening other file     ' since transposition number of rows same target number of columns     ecolumn = selection.rows.count      workbooks.open filename:="e:\pendidikan_bjn\sum.xlsx"     activesheet.cells(1, ecolumn).select     selection.pastespecial paste:=xlpasteall, operation:=xlnone, skipblanks:=false, transpose:=true     activeworkbook.save     activeworkbook.close     application.cutcopymode = false  end sub 

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 -