excel - Copying Cells from Workbook to Workbook Results in "Subscript Out of Range" -
good day.
i trying write code select cells (left right) "a - m" , (downwards) until last used row.
then, once selected, copy them workbook.
this code tried use:
activeworkbook.worksheets("sheet1").range("a1:m" & lastrow).copy _ workbooks("converter.xlsm").worksheets("sheet1").range("a1").currentregion
everything else in code works except line.
, result this:
run-time error '9': subscript out of range
thanks.
ps. "lastrow" variable used, pulled out of tutorial. that's not personal user-defined variable, not sure if that's vba's documentation.
you mentioned not have calculation lastrow.
- always put
option explicit
@ top of module. forces declare variables , recognize if got coder "built-in" or not. - see this post determining last row in range.
from post, should have calculation such following before line of code ...
lastrow = sheets("sheet1").range("a" & sheets("sheet1").rows.count).end(xlup).row
Comments
Post a Comment