PDA

View Full Version : Solved: Custome Function Returns Wrong Value



rajkumar
06-20-2009, 11:07 PM
Hi,

I am learning VBA, trying to write a custom function for me.

I need to calculate productivity per engineer that how many calls he is doing average in a day. The formula i use is
= Total calls + Broken Calls / 23 - Leaves + Holidays

I wrote a function like this ..

Function CALLSPERCE(TotalCalls, BrokenCalls, Leaves, Holidays)
CALLSPERCE = TotalCalls + BrokenCalls / 23 - Leaves + Holidays
End Function


This returns me a value of 21.2. Whereas if i use native excel functions
=SUM(A2:B2)/(23-SUM(C2:D2)) i am getting correct result (1.8)

I have no idea on what mistake i made here.

Can anybody help to correct this one. I have attached a sample workbook here.

Raj :think:

brettdj
06-20-2009, 11:11 PM
It's just an issue of putting the parentheses in the right place, ie

Function CALLSPERCE(TotalCalls, BrokenCalls, Leaves, Holidays)
Application.Volatile True
CALLSPERCE = (TotalCalls + BrokenCalls) / (23 - (Leaves + Holidays))
End Function

rajkumar
06-20-2009, 11:16 PM
Thanks Brettdj,

It worked perfectly :friends:
Raj