excel - VBA: Trying to consolidate all worksheets into one new worksheet in single workbook -
i trying copy worksheets, 1 @ time, , pasting new worksheet. these files come multiple third parties worksheets can vary. i'm running problem below when trying determine last row lrow
, last column lcol
because error appears saying object doesn't support property or method
. plan on submitting work error proofing or general macro tips appreciated.
sub ws_copy() dim lrow long dim lcol long dim pasterow long dim wscount integer dim integer 'on error resume next 'application.displayalerts = false = application.inputbox(prompt:="enter place order of first tab copied.", title:="worksheet consolidation", type:=1) if isempty(i) = true exit sub else if isnumeric(i) = false msgbox "enter numeric value." else if isnumeric(i) = true worksheets.add(before:=sheets(1)).name = "upload" wscount = worksheets.count = + 1 wscount lrow = worksheets(i).find("*", after:=cells(1, 1), _ lookin:=xlformulas, _ lookat:=xlpart, _ searchorder:=xlbyrows, _ searchdirection:=xlprevious, _ matchcase:=false).row lcol = worksheets(i).find("*", after:=cells(1, 1), _ lookin:=xlformulas, _ lookat:=xlpart, _ searchorder:=xlbycolumns, _ searchdirection:=xlprevious, _ matchcase:=false).row pasterow = lrow + 1 workbook.worksheets(i).range(cells(1, 1), cells(lrow, lcol)).copy workbook.worksheets("upload").cells(pasterow, 1).paste next else exit sub end if end if end if 'on error goto 0 'application.displayalerts = false end sub
a common way find last row/column is:
with worksheets(i) lrow = .cells(.rows.count, 1).end(xlup).row lcol = .cells(1, .columns.count).end(xltoleft).column end
hth
Comments
Post a Comment