Custom function not working - Excel 2007

teeco

New Member
Joined
Jun 8, 2010
Messages
3
Hi, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I have a problem with a custom function which does not calculate correctly. This does not seem to be an issue with manual/automatic calculation settings, nor (I think) related to whether the function is specified as volatile. <o:p></o:p>
Situation is this:
<o:p></o:p>
In different cells the function refers to a slightly different inputs.
<o:p></o:p>
Problem is that if I drag the formula down over new cells, or if any input value changes then every cell that ahs the function in it is updated with the one (and only one) result. The fact that each cell should be calculating on a different range is not reflected.<o:p></o:p>
Any ideas where I’ve gone wrong??

If its a quick solution, great - if not, I'll try to upload screen caps of my s/sheet.
For what its worth, my code is below..
thanks in advance.
<o:p></o:p>
Function WaterSum(firstWell, Rates, WellCounts)<o:p></o:p>
<o:p></o:p>
n = ActiveCell.Column - firstWell.Column<o:p></o:p>
Set period = Range(firstWell, ActiveCell.Offset(0, -n))<o:p></o:p>
<o:p></o:p>
For Each wellset In period<o:p></o:p>
monthsOnline = ActiveCell.Row - wellset.Row + 1<o:p></o:p>
monthSum = wellset.Value * WorksheetFunction.VLookup(monthsOnline, Rates, 2)<o:p></o:p>
WaterSum = WaterSum + monthSum<o:p></o:p>
Next<o:p></o:p>
<o:p></o:p>
End Function<o:p></o:p>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
What is the formula that is being dragged?
By using ActiveCell, is your intent to return the cell that holds the formula?
 
Upvote 0
I just have the function itself as the formula,

for example,
cell G6 has "=WaterSum($F$3,$A$3:$C$602,$F$3:F6)"
whereas cell G7 has "=WaterSum($F$3,$A$3:$C$602,$F$3:F7)"

The formula tries to use my function to calculate a result based on a slightly different input range (F3:F6 compared to F3:F7 in the example cells above)

I used activecell so that the input variable ($F3:F6 in above example) is set correctly, regardless of which column in the spreadsheet I invoke that function. There are probably much better ways to achieve that nut I'm not the expert I would like to be...

cheers
 
Last edited:
Upvote 0
The wellcounts argument is the only one that is different between those two formulas. And the UDF doesn't do anything with wellcounts, so the results are the same.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top