Thread: UDF Knows Range
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default UDF Knows Range

The Activecell will change as the selection changes, so when this recalcs, the answer will be
incorrect.

Function MyUdf(myAdd As Integer) As Double
MyUdf = Application.Caller.Offset(0, -1).Value + myAdd
End Function


HTH,
Bernie
MS Excel MVP


"Pranav Vaidya" wrote in message
...
Hi James,
Make sure your UDF is a public function in the module that you have. Below
is your function code..

Public Function UDF(myNum As Integer) As Integer
UDF = ActiveCell.Offset(0, -1) + myNum
End Function
--
Pranav Vaidya
VBA Developer
PN, MH-India
If you think my answer is useful, please rate this post as an ANSWER!!


"Zone" wrote:

I want my UDF to add a number to the value of the cell to the left of the
cell invoking the UDF. I don't want to specify the location of the cell. I
want the UDF to know what it is. So, if I put
=MyUdf(2) in cell B2, B2 would contain the value of A2 + 2. I thought this
would be Application.Caller, but I can't figure it out! TIA, James