vba - Copy Excel Data With Source Formatting -


i recorded macro this, , copied macro code , adapted how needed it. however, issue source formatting not kept when paste on new worksheet. step did miss? must selection.pastespecial right? below non-working syntax

selection.autofilter activesheet.listobjects("db1.accdb").range.autofilter field:=1, criteria1:="pink" lastrow = 2 worksheets("sheet2").range("a65536").end(xlup).row   next lastrow range("a1", "m" & lastrow).copy sheets.add after:=activesheet selection.pastespecial paste:=xlpasteallusingsourcetheme, operation:=xlnone, skipblanks:=false, transpose:=false range("a1").select activesheet.name = "pink" 

no need selection.pastespecial, normal copy method sufficient.

sub copytest()      '/ source             destination     '--------             -----------     sheet1.usedrange.copy sheet2.cells(1, 1)     application.cutcopymode = false  end sub 

<< --this work code.>>

sub test()      dim lastrow     long     dim rngcopy     range       selection.autofilter     activesheet.listobjects("db1.accdb").autofilter field:=1, criteria1:="pink"      set rngcopy = activesheet.usedrange      '/ rid of headers     set rngcopy = rngcopy.offset(1).resize(rngcopy.rows.count - 1)       set rngcopy = rngcopy.specialcells(xlcelltype.xlcelltypevisible)        thisworkbook.worksheets.add after:=activesheet     activesheet.name = "pink"      rngcopy.copy thisworkbook.worksheets("pink").cells(1, 1)     application.cutcopymode = false  end sub 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -