excel vba - VBA - annoying copy and paste issue -
i struggling code , don't understand why it's causing issue.
activesheet.range("b1:e" & lastrow).copy activesheet.range("b1").select selection.pastespecial xlpastevalues activesheet.name = startday & "_" & startmonth & "_" & startyear
this keeps generating error on line three.
originally had "range("b1").pastespecial" etc, pasting open workbook, though not active sheet.
i have tried 70 or 80 different possible alternative approaches, , cannot regard simple - namely copy range , paste them values in same location, in same sheet.
activesheet
can cause problems, have read how avoid using select
, active...
elements activesheet
.
essentially, make sure qualify each reference worksheet
specifying workbook
worksheet in.
thisworkbook.worksheets("someworksheet").range("b1:e" & lastrow).copy thisworkbook.worksheets("anotherworksheet").range("b1").pastespecial xlpastevalues thisworkbook.worksheets("yetanotherworksheet").name = startday & "_" & startmonth & "_" & startyear
if actions related same worksheet, can simplify things using with
token:
with thisworkbook.worksheets("someworksheet") .range("b1:e" & lastrow).copy .range("b1").pastespecial xlpastevalues .name = startday & "_" & startmonth & "_" & startyear end
Comments
Post a Comment