excel - Create worksheets based on a master worksheet and then rename each tab -
i want create worksheets list of "projects" master worksheet. when worksheet created want renamed project number list.
i found 2 macros job need them work together.
this 1 creates tabs , renames them.
sub createsheetsfromalist() dim mycell range, myrange range set myrange = sheets("invoice summary").range("b11") set myrange = range(myrange, myrange.end(xldown)) each mycell in myrange sheets.add after:=sheets(sheets.count) 'creates new worksheet sheets(sheets.count).name = mycell.value ' renames new worksheet next mycell end sub
this 1 copies master tab , creates worksheet.
sub test() dim ws1 worksheet set ws1 = thisworkbook.worksheets("master") ws1.copy thisworkbook.sheets(sheets.count) end sub
assuming there no worksheet named "master (2)" in workbook, code should work:
sub createsheetsfromalist() dim ws1 worksheet set ws1 = thisworkbook.worksheets("master") dim mycell range, myrange range set myrange = sheets("invoice summary").range("b11") set myrange = range(myrange, myrange.end(xldown)) each mycell in myrange ws1.copy thisworkbook.sheets(sheets.count) thisworkbook.worksheets("master (2)").name = mycell.value next mycell end sub
it seem odd there no worksheet object returned worksheet.copy method.
one thing note when using xldown end range -- if have 0 cells or 1 cell in range, xldown extend way last row of worksheet, produce undesirable behavior. in case, you'll error when attempting rename target sheet, out for.
Comments
Post a Comment