This Excel VBA Macro is too Slow -
is there way speed code. new vba (only started week) , i've made attempt @ writing macro automatically calculate amount of money required borrowed based on financial model.
to give context, cell informs peak borrowing requirement (pbr) cell on worksheet when increase value of facility required (fr) pbr due interest , various other charges on amount being borrowed.
i've created series of while loops fr value closest 10,000 is incredibly slow. i'm sure there must more elegant way write cant seem able figure out. preferably turn function rather sub i'm not sure if possible.
here code far, give appreciated!
' sub procedure calculate peak borrowing requirement' sub calculatefacilityrequiredbutton() dim pbr long ' stores initial peak borrowing requirement viability page dim fr long ' stores facility required inputs page ' set pbr variable value viability page worksheets("viability").activate pbr = cells(9, "k").value ' set starting value @ current peak borrowing rate viability page worksheets("viability").activate fr = cells(9, "k").value while fr <= pbr if fr <= pbr fr = fr + 1000000 worksheets("inputs").activate range("n47").value = fr worksheets("viability").activate pbr = cells(9, "k").value end if loop while fr > pbr + 100000 if fr > pbr + 100000 fr = fr - 100000 worksheets("inputs").activate range("n47").value = fr worksheets("viability").activate pbr = cells(9, "k").value end if loop while fr > pbr + 10000 if fr > pbr + 10000 fr = fr - 10000 worksheets("inputs").activate range("n47").value = fr worksheets("viability").activate pbr = cells(9, "k").value end if loop worksheets("inputs").activate end sub
your while
loop seem have same condition if
condition. can see, ever perform 1 loop in while
loop. don't think need while
loops. also, others have mentioned, don't try activating sheets. qualify sheet as:
dim ow worksheet: set ow = thisworkbook.worksheets("viability")
you can use ow.range("n47").value = fr
. should point in right direction
Comments
Post a Comment