VBA Excel Generate Unique Pages From Template and List -
i have been working on sometime (i not experienced in vba @ all), keep getting errors here are.
setup: simplicity purposes have 2 worksheets in workbook. first, "daily order", list of products, each row being different product (approx. 1,000), each column indicating different information product (ie id, cost, weight, etc).
second, "template", pricing template that, when given product information, generate pricing table.
objective: create vba macro loop through each row of "daily order" worksheet , each row make copy of template sheet , append information new sheet.
what doesn't work:
sub generatepricebook() dim rw range dim temp worksheet dim ws worksheet dim daily worksheet set daily = worksheets("daily order") set temp = worksheets("template") temp.activate each rw in daily.rows temp.copy after:=sheets(sheets.count) set ws = sheets(sheets.count) ws.name = rw.value ws .range("a6").formula = "='daily order'!b" & rw.row .range("b6").formula = "='daily order'!b" & rw.row .range("a3").formula = "='daily order'!q" & rw.row .range("e36").formula = "='daily order'!m" & rw.row .range("e36").formula = "='daily order'!y" & rw.row .range("e37").formula = "='daily order'!l" & rw.row end next rw end sub
types of errors:
i have spent considerable time trying isolate out areas think might troublesome, keep ending either 424 errors or 1004 errors.
again, appreciate help. thank you!
i think you're looking for:
sub generatepricebook() dim wsdaily worksheet dim wstemp worksheet dim lvisibility xlsheetvisibility dim strsheetname string dim rindex long dim long set wsdaily = sheets("daily order") set wstemp = sheets("template") lvisibility = wstemp.visible 'in case template sheet hidden wstemp.visible = xlsheetvisible rindex = 2 wsdaily.cells(rows.count, "a").end(xlup).row 'ensure valid sheet name strsheetname = wsdaily.cells(rindex, "a").text = 1 7 strsheetname = replace(strsheetname, mid(":\/?*[]", i, 1), " ") next strsheetname = trim(left(worksheetfunction.trim(strsheetname), 31)) 'make sure sheet name doesn't exist if not evaluate("isref('" & strsheetname & "'!a1)") wstemp.copy after:=sheets(sheets.count) sheets(sheets.count) .name = strsheetname .range("a6").formula = "='" & wsdaily.name & "'!b" & rindex .range("b6").formula = "='" & wsdaily.name & "'!b" & rindex 'you referencing same cell in a6? .range("a3").formula = "='" & wsdaily.name & "'!q" & rindex .range("e36").formula = "='" & wsdaily.name & "'!m" & rindex .range("e36").formula = "='" & wsdaily.name & "'!y" & rindex 'you putting second formula in e36? .range("e37").formula = "='" & wsdaily.name & "'!l" & rindex end end if next rindex wstemp.visible = lvisibility 'set template sheet original visible state set wsdaily = nothing set wstemp = nothing end sub
Comments
Post a Comment