View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default How to pass cell reference to VBA function?

You need the double quotes because you are passing in a string. Something
like:

Function plus1(r As Range) As Long
plus1 = r.Value + 1
End Function

will allow you to use =plus1(A1) in the worksheet.
--
Gary's Student


" wrote:

I want to define something like:

function mycell(ref)
mycell = range(ref).something
end function

That works if I call it from a spreadsheet formula
in the form mycell("A1"). But I want to call it in
the form mycell(A1) -- no quotes -- so that mycell()
is recomputed if A1 changes.

How can I do that? That is, how do I declare "ref",
and/or how do I pass A1 so that it can be used in
the VBA range() function, without passing "A1" as
a string?

Note: I am using Office Excel 2003, if that matters.