How to write a average formula in excel vba -
i trying calculate average, getting run-time error. here code..
lastrowcell = range("b1", range("b1").end(xldown)).rows.count range("f1").value = "high+low/2" n = 2 lastrowcell range(cells(n, 6)).formula = "=average(" & range(cells(n, 2), cells(n, 3)).address(false, false) & ")" next
can show did wrong.
thanks in advance...
you don't need loop, excel smart enough fill entire thing in 1 go:
lastrowcell = range("b1", range("b1").end(xldown)).rows.count range("f1").value = "high+low/2" range("f6:f" & lastrow).formula = "=average(b6:c6)"
the 6 incremented in each row
if want last row though, better come bottom unless looking first blank:
lastrowcell = range("b" & rows.count).end(xlup).row
Comments
Post a Comment