MrExcel Publishing
Your One Stop for Excel Tips & Solutions

help with macro


Posted by harry on December 13, 2001 7:30 AM

i need to make a macro that takes two columns of values (x,y) and calculates the integral by using the formula SUM[(x2-x1)*(y2-y1) + (x3-x2)*(y3-y2) + ...] and loops for any length list of numbers ie and outputs the summed value in a single cell.


Posted by bob Umlas on December 13, 2001 7:51 AM

Function Untested(Xrange as Range, YRange as range)
tot=0
For i=2 to xrange.rows.count
tot=tot+(Xrange.cells(i)-xrange.cellx(i-1))*(Yrange.cells(i)-Yrange.cells(i-1))
Next
Untested=tot
End Function

In the worksheet, enter
=UNTESTED(A1:A50,B1:B50), for example -- should work!