Hello everyone
how can this formula be converted to a UDF?
Thank you in advance=IF(A2<>"no";TRUNC(H2*B2;2)*E2+TRUNC(H2*B2;2)/30*D2+TRUNC(H2*C2;2)*G2+TRUNC(H2*C2;2)/30*F2;"")
Hello everyone
how can this formula be converted to a UDF?
Thank you in advance=IF(A2<>"no";TRUNC(H2*B2;2)*E2+TRUNC(H2*B2;2)/30*D2+TRUNC(H2*C2;2)*G2+TRUNC(H2*C2;2)/30*F2;"")
It looks like you're on Excel2010 so you can't take advantage of some of the newer functions.
Your formula could be shorter:Anyway, a UDF:=IF(A2<>"no";TRUNC(H2*B2;2)*(E2+D2/30)+TRUNC(H2*C2;2)*(G2+F2/30);"")On a spreadsheet:Function TheCalc(condn, theVal, Pcnt1, Mnths1, Days1, Pcnt2, Mnths2, Days2) If condn <> "no" Then TheCalc = Evaluate("trunc(" & theVal * Pcnt1 & ",2)") * (Mnths1 + Days1 / 30) + Evaluate("trunc(" & theVal * Pcnt2 & ",2)") * (Mnths2 + Days2 / 30) Else TheCalc = "" End If End Function
=TheCalc(A2;H2;B2;E2;D2;C2;G2;F2)
but with 8 arguments it'd be nice to see some hints as to what belongs where as built-in functions do, but you can get close by doing the following:
In a cell type
=TheCalc(
then while the cursor is still direclty after the open parentheses character, press CTRL + Shift + A and you should then see:
=TheCalc(condn;theVal;Pcnt1;Mnths1;Days1;Pcnt2;Mnths2;Days2)
then all you have to do is replace the hints with cell references.
Note, if you don't like the name TheCalc for the function you can change it by changing all 3 instances of it to something else in the udf.
Edit: One more thing, in the udf, in the two Evaluate bits, there's ,2 which might need to be change to ;2 (replace the comma with a semicolon)
Last edited by p45cal; 01-18-2025 at 06:25 AM.
p45cal
Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.
Very great solution. It solved my problem and I got the desired results.
Last edited by Aussiebear; 04-14-2025 at 04:15 PM.