vba - Run-time error '1004': Copy method of Range class failed Excel 2013 when adding a new pivot table -


i getting error specified in title of issue when trying copy , paste columns (and it's data) new workbook. code below used work till moment when add new sheet new pivot table in workbook, , don't know reason:

sub extractdata_2()    workbooks.add   activeworkbook.saveas thisworkbook.path & "\extract_fcst" & ".csv", 6   thisworkbook.worksheets("forecast enrichment").activate    thisworkbook.sheets("forecast enrichment").range("e:s").copy destination:=workbooks("extract_fcst.csv").sheets(1).range("a:o")    workbooks("extract_fcst.csv").sheets(1).range("a:o").entirecolumn.autofit  end sub 

does have idea how solve problem? have tried lot of different solutions found in google of works!

use object variables , assign properly, break copy/destination see whether error raises on copy or paste, follows:

sub extractdata_2()    dim csvworkbook workbook    set csvworkbook = workbooks.add   csvworkbook.saveas thisworkbook.path & "\extract_fcst" & ".csv", 6    ' unnecessary "activate" sheet...", can delete this:   ' thisworkbook.worksheets("forecast enrichment").activate    'try using copy/paste separate statements see failure may occur   thisworkbook.sheets("forecast enrichment").range("e:s").copy   csvworkbook.sheets(1).range("a1").select   csvworkbook.sheets(1).paste    csvworkbook.sheets(1).range("a:o").entirecolumn.autofit  end sub 

if still raises error, let me know line happens.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -