Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Basic UDF Question

  Asked By: Elliott    Date: Dec 19    Category: MS Office    Views: 517
  

Very basic question about UDF's.

Could someone show me sample code and worksheet formula that accepts a
cell range as input and returns some processed result?

For example, let's say I want to multiply whatever value was supplied by
5.

Function MyFunc(r As Range) As String ' Is "r as Range" correct?
MyFunc = 5 ' * something - times what?
End Function

And also, what exactly do I put as a formula on my worksheet? Something
like
=MyFunc(A1) ?

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Amy Brown     Answered On: Dec 19

Sample code:
Function myfunc(a)
myfunc = a * 5
End Function

Formula in worksheet:
=myfunc(D4)

 
Answer #2    Answered By: Mandy Harvey     Answered On: Dec 19

Strange - I keep getting a #NAME? error in the cell. I made sure to
Enable macros too.

Any clue?

 
Answer #3    Answered By: Kawthar Malik     Answered On: Dec 19

The function  needs to be in a module or you need to change the way you
reference it.

 
Answer #4    Answered By: Komal Malik     Answered On: Dec 19

I tried it so far in ThisWorkbook and also Sheet1 (the
correct sheet) to no avail...
???

 
Answer #5    Answered By: Marsha Miller     Answered On: Dec 19

right click the workbook's project title in the project explorer
part of the ve editor, click 'insert', then choose 'module'. Copy
the code  into the new module.

 
Answer #6    Answered By: Judy Gray     Answered On: Dec 19

below where it reads 've editor' should read 'vb editor' reached by
Alt+F11 when in excel.

 
Answer #7    Answered By: Bernadette Daniels     Answered On: Dec 19

Can anyone explain please;

Which kind of codes should locate in "Module(s)" and which are in "This
workbook" or "Sheet(s)"

 
Didn't find what you were looking for? Find more on Basic UDF Question Or get search suggestion and latest updates.




Tagged: