Referring to a range of cells inside a formula in VBA Excel -
i'm trying use vba in order calculate fields. when record macro this:
activecell.formular1c1 = "=averageif(r4c[-27]:r4c[-6],2012,rc[-27]:rc[-6])"
the problem range formula can change.
i have integer variable numofmon
counts required columns formula first column on sheet. formula above however, uses offsets determine required range because range can change need use numofmon in order use required cells. how can change formula can use properly?
i tried using variables this:
a = 28 numofmon = 21 activecell.formular1c1 = "=averageif(r4c[-(a-1)]:r4c[-(a-numofmon-1)],2012,rc[-(a-1)]:rc[-(a-numofmon-1)])"
but error: "application defined or object defined error"
basically
activecell.formular1c1 = "=averageif(r4c[-" & (a-1) & "]:r4c[-" & (a-numofmon-1) & "],2012,rc[-" & (a-1) & "]:rc[-" & (a-numofmon-1) & "])"
Comments
Post a Comment