tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,834
- Office Version
- 365
- 2019
- Platform
- Windows
I have created a udf but I can't work out why it gets called more than once?
In Sheet1, I have values in cells B1, D1 and E1.
A1 contains a formula:
and C1 contains my udf:
Here is the code:
What I don't understand is why does this line of code:
trigger the udf?
Is it because the udf takes two arguments, which are A1 and B1, so changing A1 and / or B1 triggers the udf?
Thanks
In Sheet1, I have values in cells B1, D1 and E1.
A1 contains a formula:
Code:
=D1+E1
and C1 contains my udf:
Code:
=MyCalc(B1,A1)
Here is the code:
Code:
Option Explicit
Sub Test()
Sheet1.Cells(1, 1).FormulaR1C1 = "=RC[3]+RC[4]"
Sheet1.Cells(1, 3).FormulaR1C1 = "=MyCalc(RC[-1],RC[-2])"
End Sub
Public Function MyCalc(Metric1 As Integer, Metric2 As Integer) As Integer
MyCalc = Metric1 + Metric2
End Function
What I don't understand is why does this line of code:
Code:
Sheet1.Cells(1, 1).FormulaR1C1 = "=RC[3]+RC[4]"
trigger the udf?
Is it because the udf takes two arguments, which are A1 and B1, so changing A1 and / or B1 triggers the udf?
Thanks