views:

171

answers:

2

I am creating a spreadsheet which has a column of data, and I would like to calculate the varaince of x number of rows based on x inputed. Any advice?

A: 

Please look at the VAR and INDIRECT functions, then come back with a more specific question (and preferably an example). I am not convinced this requires VBA.

Matthew Flaschen
+1  A: 

As Matthew Flaschen suggests, there is no need for VBA. This can be done with Excel formulae.

Suppose your data is in column A, starting at A1 and going down. Suppose cell B1 has the number x, which is the sample size you wish to use.

Then the formula you need should be:

=VAR(OFFSET(A1,0,0,B1,1))

The VAR part says calculate the variance of a sample of the population, ignoring non-numbers. (Variants to the function include VARP for the entire population, VARA to include non-numbers and VARPA for both).

The Offset part says to start at cell A1, move 0 columns across and zero columns down, and then select a range which is B1 columns tall and one column wide.

Oddthinking
I would suggest changing the code to use absolute references like VAR(OFFSET($A$1,0,0,$B$1,1)).
Ian Roke
Sure, that'd help if you might be copying-and-pasting the formula.
Oddthinking