View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default A simple function

Public Function func(range1, range2)
Dim r1, r2 As String
r1 = range1.Value
r2 = range2.Value
func =r1+r2
End Function

Put the code in a general module, not in the Sheet module.

you get a general module by doing insert=Module in the VBE with your
workbook the active project in the VBE.

--
Regards,
Tom Ogilvy


Bob Grossman wrote in message
...
My appologies.

The code is:

Public Function func(range1, range2)
Dim r1, r2 As String
r1 = range1.Value
r2 = range2.Value
MsgBox (r1+r2)
End Function

Obviously, I have some enhancements in mind once I figure out how to
make this simple example work.

Bob.

On Fri, 29 Aug 2003 22:58:49 +0100, "Phobos"
wrote:

It would help if you posted the code.

P


"Bob Grossman" wrote in message
.. .
It has been 8 or so years since I did anything in excel, please excuse
the simple question.

In cells a1 and b1 I have a string stored. In cell c1 I would like to
have a function I have written ( = Module1.func(a1,b1) ).

Function func will return a value to cell c1.

I must be doing something stupid because excel flags the cell with a
#NAME? error.

Can someone explain how to make this work?

Thanks in advance, Bob.