The following function takes no arguments and returns the value in the cell 3 columns to the left.
Function NANA() As Variant
Application.Volatile
NANA = Application.Caller.Offset(0, -3).Value
End Function
So typing =NANA() in C3 will give the contents of C1 for example.
How can i make argument say one for loaction offset to fix cell, that code woks perfect, just imtrested a big thanks
If you change it to
Function NANA(Offset As Integer) As Variant
Application.Volatile
NANA = Application.Caller.Offset(0, Offset).Value
End Function
then the function accepts one argument - how many columns to offset by.
As i've read on http://www.decisionmodels.com/ in the UDF's chapter, it's a very good thing to put every variable that the formula uses as an argument, and avoid, when possible, the use of Application.Volatile, because, this too, force Excel to recalculate the formula each time any cell changes, and not the one that specifically is used by the UDF, taking more time and resources.
That said, i would change the proposed UDF to this:
Public Function NANA(Rng as Range) as Variant
Dim DRow as Long
Dim DCol as Single
DRow = Application.Max(1,Rng.Row - 2)
DCol = Rng.Column
NANA = Cells(DRow,DCol)
End Function
The example isn't clear if the expected result is two rows up and two columns to the left, or only two rows up.
Juan Pablo G.
What do i say guys all good stuff, and i have loads to try, i really enjoy the challenge but my skills suffer sometimes, now to make all pretty with comments of waht to do in that box like MS foruuls, and so on, i must thanks you again,
Jack in UK
What do i say guys all good stuff, and i have loads to try, i really enjoy the challenge but my skills suffer sometimes, now to make all pretty with comments of waht to do in that box like MS foruuls, and so on, i must thanks you again,
Jack in UK