Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run EXCEL formula in VBA function

I have a custom function in VBA which I call from cell and I have a formula like this

"=SUM(SUMIFS(CURR_COUNT;MDL;""MODEL"";CURR_MDLCD;{CODES};RG;""REGIONID""))/SUM(SUMIFS(CURR_COUNT;MDL;""MODEL"";RG;""REGIONID"";CURR_MDLCD;""<>     ""))"

My custom function take some cells values and insert them to formula which is just string. After that I need to calculate formula and return result to cell from which I call the function? Can I calculate this formula in the function and return result to a cell?

like image 643
mojo Avatar asked Oct 16 '25 17:10

mojo


1 Answers

Assuming your formula string would work if it was actually put into a cell, then it should work if you use Application.Evaluate - but you don't include the equals sign.

e.g. To calculate

=SUM(A1:B1)

in VBA you would use

Application.Evaluate("SUM(A1:B1)")
like image 162
zaphodalive Avatar answered Oct 18 '25 06:10

zaphodalive



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!