ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   what's the problem with this ? (https://www.excelbanter.com/excel-programming/380147-re-whats-problem.html)

Gary''s Student

what's the problem with this ?
 
Function mySP(rng1 As Range, rng2 As Range, dec As Integer) As Double
Dim v As Double, IamTheCount As Long
IamTheCount = rng1.Count
mySP2 = 0
For i = 1 To IamTheCount
v = Round(rng1.Cells(i, 1).Value * rng2.Cells(i, 1).Value, dec)
mySP2 = mySP2 + v
Next
End Function


So that if B1 thru C5 a

1.0234 0.45678
2.001 2.7
3.3 3
4.4 4
5.6543 5

then
=mySP(B1:B5,C1:C5,3)
will return 61.642

--
Gary's Student


"dribler2" wrote:

so short am i not to know the solution..never know the programming language.

anyone know how to make this UDfunction work..

Function mySP(rng1 As Range, rng2 As Range, Optional dec As Long = 2)
mySP = Application.Caller.Parent.Evaluate("SumProduct(Rou nd(" & rng1 * rng2,
dec & "))")
End Function

'syntax =mySP(A1:A100,B1:B100,1) ----SUM OF ROUNDED PRODUCT MADE OF 2 FACTOR
ONLY

happy holidays...
driller.



All times are GMT +1. The time now is 06:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com