Sabtu, 22 Oktober 2016

Re: [ExcelVBA] failing function


Dear Greg

This worked for me :-

Public Function Func(x As Range, y As Range) As Variant
' ---- my code ----
    Func = "My result"
End Function

In the spreadsheet I put :-
=PERSONAL.XLSB!Func( A5:E5,A6:E6), -  i.e. the full path to the Function.

You cannot directly run a Function in the VBA IDE, you have to call it from a Sub. That is why it asks for a Macro name.

You don't need the ByVal unless you are modifying the ranges in your code. ByRef is implicit.

Returning a Variant type to the spreadsheet makes it more resilient while you are developing.


Derek Turner

From: "'David Smart' [ExcelVBA]" <>
Sent: Friday, 21 October 2016, 23:50
Subject: Re: [ExcelVBA] failing function


"Public"?  I.e.
Public Function Func(ByVal x as range, y as range) as variant
Not sure about the ByVal on the range, either.  You might need ByRef on both parameters.  As in
Public Function Func(ByRef x as range, ByRef y as range) as variant
Lastly, avoid a return type of Variant if you can - give it a more appropriate return type (unless, of course, you are returning various types).

Regards, Dave S
----- Original Message -----
Sent: Saturday, October 22, 2016 1:09 AM
Subject: [ExcelVBA] failing function

I am trying to create a Function

I create a module (module1 in General Declaration)

I put in the code
Function Func(ByVal x as range, y as range) as variant
---- my code ----
Function End

in the spreadsheet I put in   =Func(A1:E1,A2:E2)

The results are VALUE error
I try to run the Function in VBA Editor and it keeps asking for a Macro Name.

I am missing something simple I am sure, but what is it?

Thanks for responding to this.


Posted by: Derek Turner <>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.

Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: to enter the ezine, then search the ARCHIVES for EXCEL VBA.

Visit our ExcelVBA group home page for more info and support files:

More free tutorials and resources available at:




Tidak ada komentar:

Posting Komentar