loops - Excel VBA - Work with Subgroup of Array -
i have 1-dimensional array 1000 entries. loop through parts of array , apply calculate average on subgroup. have done far looks this:
temp = array(myarray) temp_range = application.index(temp, evaluate("row(1:10)")) average(i) = application.average(temp_range)
by can calculate average of first 10 rows. not dynamic @ all, , wondering if there way of working subgroups of array (so can loop through them)?
thanks help, can't figure 1 out...
update: tried code here st.dev (not average). works! much. however, code slow. there way of making faster?
here loop: return array of 1000 returns. aim calculate standard deviation of 1 year of daily return data.
= 2 n if year(dates(i)) > year(dates(i - 1)) test = application.index(return, evaluate("row(" & c & ":" & (i - 2) & ")")) vola(m) = application.stdev(test) * sqr(252) m = m + 1 c = - 1 else test = application.index(return, evaluate("row(" & c & ":" & (i - 1) & ")")) on error resume next vola(m) = application.stdev(test) * sqr(252) end if next
without knowing more how you're looping through these, could:
dim frstrow long, lstrow long 'within loop, assign values frstrow, lstrow temp_range = application.index(temp, evaluate("row(" & frstrow & ":" & lstrow &")"))