excel - Creating a formula, Same cell, Dynamic number of sheets -
i have created workbook has 2 sheets there: "master" , "score". on master sheet have named dynamic range inputting names, instance(mike, sheila, tom, , matt) have macro take list of names , create separate sheets. list can vary 3 20.
sub create_ws() dim mycell range, myrange range dim newname string set wb1 = thisworkbook set ws2 = wb1.sheets("master") 'this macro create separate tabs based on list in master tab k2 down set myrange = ws2.range("k2") set myrange = range(myrange, myrange.end(xldown)) screen 0, 1 each mycell in myrange if sheetexists(mycell) newname = inputbox("sheet exists, please specify unique name!", "new copy") if newname = vbnullstring or newname = "" screen 1 exit sub end if sheets.add after:=sheets(sheets.count) sheets(sheets.count).name = (newname) else sheets.add after:=sheets(sheets.count) 'creates new worksheet sheets(sheets.count).name = mycell.value ' renames new worksheet format_tabs (mycell) 'calls next process add named tabs end if next mycell screen 1 ws2.select end sub on each sheet format same: column , b pre-filled data , columns c, d,and e person fill in scoring information. sheets , rows vary, columns needed average same.
what looking on "score" sheet develop macro build formula average responses in each sheet not static names , put them correct cell on scoring sheet. instance if there 11 issues formula placed in c2, d2, e2, c3, d3, e3...all way c12, d12, e12. in cell c2 on score sheet formula should read =average(mike!c2,sheila!c2,tom!c2,matt!c2) , in cell d2 formula read =average(mike!d2,sheila!d2,tom!d2,matt!d2)
my named range greviewers , starts on master!k2. have helper cells looking automate workbook expand knowledge vba.
here code found. sums sheets need , puts in cell need go in, need average , if formula display in cell able use .filldown.
sub totals() dim c range, mytotal double mytotal = 0 each c in range("greview") mytotal = mytotal + sheets(c.value).range("c2") next c thisworkbook.worksheets("score").range("c2") = mytotal end sub
so after playing , researching able solve own question. if have neater way code please feel free add on.
sub b_form() dim c range dim myform string dim r long dim x long mytotal = 0 x = 1 thisworkbook.sheets("score").select cells(1, 1).select ' count rows in named range dim orng range, lrows long lrows = 0 each orng in range("greview").areas lrows = lrows + orng.rows.count next orng 'gets sheetnames , cells build dynamic formula r = 3 5 each c in range("greview") if x <> lrows myform = myform + c & "!" & cells(2, r).address(rowabsolute:=false, columnabsolute:=true) & "," else myform = myform + c & "!" & cells(2, r).address(rowabsolute:=false, columnabsolute:=true) end if x = x + 1 next c thisworkbook.worksheets("score").cells(2, r) = "=average(" & myform & ")" myform = "" x = 1 next r ' calculation no longer needed @ time 'sheets("score").range("f2") = "=($c2*$d2)-(($c2*$d2)*($e2/5))" lr = get_lr(2) sheets("score").range("c2:e" & lr) .filldown end end sub
Comments
Post a Comment