Calculating Data in VBA Excel Where conditions can vary -


i coaching rifle shooting team , designing program analyse data, data required stored in large denormalized on sheet in excel. hoping calculate statistics each shooter such average score, top score, std dev etc. how ever on summary sheet need bunch of variables filter data such day of year, time of day, distance shot, year.

i attempting design own fuctions such

public function avescore(shooterid string, yearshot integer, optional day string = "all year", optional timeofday string = "all day", optional distance string = "all", optional outof integer = 40, optional topshots integer = 0, optional adjoutof boolean = true) double 

this able call on sheets , allow me adapt format. due nature of filters filter data , other times data in areas. each filter corresponds field in table.

i found using loops calculate results ended many many overwhelming if statements unrealistic because had account each eventuality when conditions needed or not

the following attempt writing creating excel formula through if statements evaluating this

public function avescore(shooterid string, yearshot integer, optional day string = "al year", optional timeofday string = "all day", optional distance string = "all", optional outof integer = 40, optional topshots integer = 0, optional adjoutof boolean = true) double 'if topshots 0 no top , show shots  dim formula string: formula = "{=average(" dim top boolean: top = false dim integer  'check if want @ top shots if topshots <> 0     top = true     formula = formula + "large(" end if 'add 2 if statements check year , shooterid formula = formula + "if(denormalizedtable[year]=" & yearshot & ",if(denormalizedtable[shooterid]=" & chr(34) & shooterid & chr(34) & ","  dim counter integer: counter = 2  'check if day or period add if statement if day <> "all year"     set c = lists.range("periodlist").find(day, lookin:=xlvalues, lookat:=xlwhole)     if not c nothing         formula = formula + "if(denormalizedtable[period]=" & chr(34) & day & chr(34) & ","         counter = counter + 1     else         set c = lists.range("daylist").find(day, lookin:=xlvalues, lookat:=xlwhole)         if not c nothing             formula = formula + "if(denormalizedtable[day]=" & chr(34) & day & chr(34) & ","             counter = counter + 1         end if     end if end if  'and time of day if if timeofday <> "all day"     formula = formula + "if(denormalizedtable[timeofday]=" & chr(34) & timeofday & chr(34) & ","     counter = counter + 1 end if  'add distance if if distance <> "all"     formula = formula + "if(denormalizedtable[distance]=" & distance & ","     counter = counter + 1 end if  formula = formula + "denormalizedtable[%score]"  'add brackets ifs = 1 counter     formula = formula + ")" next  if top     formula = formula + ",{"     = 1 topshots         formula = formula +         if <> topshots             formula = formula + ","         end if     next     formula = formula + "})" end if  formula = formula + ")*" & outof & "}" msgbox formula avescore = evaluate(formula) end function 

how ever function seems impractical , unextendable other functions wish write

i hoping able suggest way might achieve analysis practical

i new coding , not have best knowledge of prebuilt functions have done lots of research , not find me


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -