proc expandStat f {

	global CellValues CellFormulae
#	We have an expression possibly containing a cell range!
#	sum($E6.$E8)
#	avg($A8.$C10)
#	we have to translate these into a legit expression

	set p [cindex $f 3]
	if {$p != "("} {
		return ERR
	}

	set func [crange $f 0 2]
	set range [crange $f 4 end-1]

	lassign [split $range .] cr1 cr2
	if {[cindex $cr1 0] != "\$"} {
		return ERR
	}

#	get beginning and ending cell indices

	set rcb [cellIndex [crange $cr1 1 end]]
	set rce [cellIndex $cr2]
	lassign [split $rcb ,] r1 c1
	lassign [split $rce ,] r2 c2
	set ct 0
	set sum 0

	loop i $r1 [expr $r2 + 1] {
		loop j $c1 [expr $c2 + 1] {
			set v ""
			set ind "$i,$j"
			catch {[set v $CellValues($ind)]}
			lappend depends $ind
			if {$v != "<empty>"} {
				set err [catch {expr $v}]
				if !$err {
					set sum [expr $sum + $v]	
					incr ct
				}
			}
		}
	}

	set avg [expr $sum / [double $ct]]
	
	if {$func == "sum"} {
		return [list $sum $depends]
	} else {
		return [list $avg $depends]
	}
}

