excel - Copy from one workbook into another using a file path name -
i trying run macro using existing workbook 1) opens different workbook i'll call other 2) copies values other workbook 3) pastes values other existing workbook , 4) closes other workbook. below code have far. there way better define or set y? code works except not able close other , think if had y better defined use y.close. thanks!
dim x worksheet dim y worksheet set x = activeworkbook.sheets("file44") workbooks.open (thisworkbook.path & "\file44.xlsm") workbooks("file44.xlsm").activate set y = activeworkbook.sheets("file44 - detail") lastrow = y.range("a" & rows.count).end(xlup).row y.range("a15:cq" & lastrow).copy x.range("a2").pastespecial xlpastevalues activeworkbook.close savechanges:=false
untested
sub chris2015() dim other workbook dim fromws worksheet dim tows worksheet dim lastrow long set tows = thisworkbook.sheets("file44") 'pasting worksheet set other = workbooks.open(thisworkbook.path & "\file44.xlsm") set fromws = other.sheets("file44 - detail") lastrow = fromws.range("a" & fromws.rows.count).end(xlup).row tows.range("a2:cq" & lastrow - 13).value2 = fromws.range("a15:cq" & lastrow).value2 'hope did math right xd other.close savechanges:=false end sub
Comments
Post a Comment