UDF recalculates all cells unexpectedly

mirology

New Member
Joined
Oct 9, 2015
Messages
20
I 've created a custom function to estimate a factor based on 2 ranges : Well , AllWells ... what it does is it finds the last non empty cell in each column of allwells range and calculate : factor= Well/Sum(last cells in allwells.range) ....

so my problems are :
When i update unrelated cells... the whole table recalculates ( processors 4 calculating 0 % ) ... etc
When i add new row to my table it recalculates the 1100 cells again

The weird thing is when I change the related cells it only recalculates the adjacent cell with my custom function not the whole table like others !!!!!!

I've tried to make it as less volatile as possible but i dont know what else i can do :/ and where is the problem !!!


FYI i intend to use the formula in multiple sheets and multiple tables thats why i've used application.caller method to avoid problems..




Code:
Public Function FactorMe(Well As Range, AllWells As Range)

Dim ws As Worksheet
Dim rng As Range
Set ws = Application.Caller.Worksheet


Set rng = Range(ws.Cells(4, Well.Column), ws.Cells(Well.Row, Well.Column))




 Lrow = rng.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row


WellValue = ws.Cells(Lrow, Well.Column).Value


totalsum = 0
For i = AllWells.Column To AllWells.Column + AllWells.Columns.Count - 1
Set rng = Range(ws.Cells(4, i), ws.Cells(Well.Row, i))


Lrow = rng.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row


totalsum = totalsum + ws.Cells(Lrow, i).Value


Next
If totalsum = 0 Then
FactorMe = 0
Exit Function
End If
FactorMe = WellValue / totalsum


End Function
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,216,482
Messages
6,130,928
Members
449,607
Latest member
babylegs

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