vba - Excel Visual Basic Application-defined or Object-defined error -
so have 2 excel worksheets in 1 workbook. there bigger 1 called "data" , smaller 1 called "sheet1." code below first creates new sheet called "dailyreport" , compare 2 sheets. if 1 cell column b of "sheet1" same 1 cell in column b of "data", should copy row in "data" new sheet "dailyreport." below code. macro. keeps saying "invalid procedure call or argument"error.
sub dailyreportgenerator() sheets.add.name = "dailyreport" application.screenupdating = false dim startnumber integer dim endnumber integer dim startnumber2 integer endnumber = 9999 startnumber = 1 endnumber startnumber2 = 1 endnumber if worksheets("sheet1").cells(startnumber, "b").value = worksheets("data").cells(startnumber2, "b").value sheets("data").range(sheets("data").cells(startnumber, "b"), sheets("data").cells(startnumber, "ca")).copy sheets("dailyreport").cells("startnumber, b") end if next startnumber2 next startnumber application.screenupdating = true end sub
edited:
sub dailyreportgenerator() const endnumber long = 999 dim shtrpt worksheet, shtdata worksheet, shtsheet1 worksheet dim rwnumsht1 long, rwnumdata long set shtrpt = sheets.add() shtrpt.name = "dailyreport" set shtdata = worksheets("data") set shtsheet1 = worksheets("sheet1") application.screenupdating = false rwnumsht1 = 1 endnumber rwnumdata = 1 endnumber if shtsheet1.cells(rwnumsht1, "b").value = shtdata.cells(rwnumdata, "b").value shtdata .range(.cells(rwnumdata, "b"), .cells(rwnumdata, "ca")).copy _ shtrpt.cells(rwnumsht1, "b") end end if next rwnumdata next rwnumsht1 application.screenupdating = true end sub
Comments
Post a Comment