Using VBA function as worksheet function?

N

Nekdo Od Nekje

Hello?

Anybody knows if is it posible (and how) to define a VBA
function to use it as a worksheet function. I tried and I
defined a such test one but I always got the #NAME? error
on worksheet?

NON
 
F

Frank Kabel

Hi
in a module of your workbook try

Public Function foo(rng as range) as integer
' insert your code and adapt the function parameters....
foo = 1
End Function

Frank
 
N

Norman Harker

Hi Nekdo!

Here's a simple one:

Function COLOR(MyCell As Range)
COLOR = MyCell.Interior.ColorIndex
End Function

This function will be usable provided it is in an open workbook, the
Personal.xls (which is an open workbook), or in an Addin that has been
installed and selected as an Addin.


--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
N

Nekdo Od Nekje

Thanks, it works!

I tried to insert my code in Microsoft Excel Object in
Sheet1 and in ThisWorkbook. It was obviosly the wrong
place!?

NON
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top