excel - Mathematical equation in vba -
i have mathematical equation performing in sheet "accrued expenses
" on range("e7")
. formula intend loop till lastrow in column c 2 key sheets "start page" , "accrued expenses" .
the problem i not able vba code. works using excel macro recorder, wont efficient maintenance. equation , code below.
=('accrued expenses'!c7*'start page'!$f$5)/'start page'!$f$13*'accrued expenses'!d7
in excel recorder code , loop:
option explicit sub calculating_accruedexpense() sheets("accrued expenses").select dim lastrow long lastrow = activesheet.range("c" & rows.count).end(xlup).row range("e7").select until activecell.row = lastrow + 1 if isempty(activecell) activecell.formular1c1 = _ "=('accrued expenses'!rc[-2]*'start page'!r5c6)/'start page'!r13c6*'accrued expenses'!rc[-1]" end if activecell.offset(1, 0).select loop end sub
excel recorder line:
activecell.formular1c1 = _ "=('accrued expenses'!rc[-2]*'start page'!r5c6)/'start page'!r13c6*'accrued expenses'!rc[-1]"
try this:
sub calculating_accruedexpense() dim lastrow long, cl range lastrow = worksheets("accrued expenses").range("c" & rows.count).end(xlup).row each cl in range("e7:e" & lastrow) if isempty(cl) cl = (cl.offset(0, -1) * worksheets("start page").range("f5")) / worksheets("start page").range("f13") * cl.offset(0, -2) end if next cl end sub
Comments
Post a Comment