Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default use vba function in formula

Hi !

Is ther any way to use some vba function i wrote in my cells formulas ??

for example : =myfunction(A1:A10)

with

function myfunction (myRange as range)
.....
end Function

Thank you all for your answers

Sylvain Caillet


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default use vba function in formula

Hi
if you don't declare the function as private and put it in a standard
module you can simply use your function as you would use a worksheet
function.
Also see
http://www.mvps.org/dmcritchie/excel/getstarted.htm

--
Regards
Frank Kabel
Frankfurt, Germany

"news.wanadoo.fr" schrieb im Newsbeitrag
...
Hi !

Is ther any way to use some vba function i wrote in my cells formulas

??

for example : =myfunction(A1:A10)

with

function myfunction (myRange as range)
....
end Function

Thank you all for your answers

Sylvain Caillet



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default use vba function in formula

Thank you for your quick reply but i need one more information, please.

What should be the return type of my function to be useable as argument for
other standard functions in formulas, such as Sum, Correlation coefficient
calculus, ... ?

I have tried the following function, but it doesn't work :

Public Function myRange(chaine As String) As Range
plage = Sheets("Référence").Range(chaine)
End Function

If i write a formula such as
=SUM(myRange("B29:B31"))
It doesn't work.

Thank you for your help !

Sylvain Caillet



"Frank Kabel" a écrit dans le message de news:
...
Hi
if you don't declare the function as private and put it in a standard
module you can simply use your function as you would use a worksheet
function.
Also see
http://www.mvps.org/dmcritchie/excel/getstarted.htm

--
Regards
Frank Kabel
Frankfurt, Germany

"news.wanadoo.fr" schrieb im Newsbeitrag
...
Hi !

Is ther any way to use some vba function i wrote in my cells formulas

??

for example : =myfunction(A1:A10)

with

function myfunction (myRange as range)
....
end Function

Thank you all for your answers

Sylvain Caillet





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default use vba function in formula

Sylvain,

You need to return the Function name to the caller. and range is an object
so you need to Set it

Public Function myRange(chaine As String) As Range
Set myRange = Sheets("Référence").Range(chaine)
End Function
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Sylvain" wrote in message
...
Thank you for your quick reply but i need one more information, please.

What should be the return type of my function to be useable as argument

for
other standard functions in formulas, such as Sum, Correlation coefficient
calculus, ... ?

I have tried the following function, but it doesn't work :

Public Function myRange(chaine As String) As Range
plage = Sheets("Référence").Range(chaine)
End Function

If i write a formula such as
=SUM(myRange("B29:B31"))
It doesn't work.

Thank you for your help !

Sylvain Caillet



"Frank Kabel" a écrit dans le message de news:
...
Hi
if you don't declare the function as private and put it in a standard
module you can simply use your function as you would use a worksheet
function.
Also see
http://www.mvps.org/dmcritchie/excel/getstarted.htm

--
Regards
Frank Kabel
Frankfurt, Germany

"news.wanadoo.fr" schrieb im Newsbeitrag
...
Hi !

Is ther any way to use some vba function i wrote in my cells formulas

??

for example : =myfunction(A1:A10)

with

function myfunction (myRange as range)
....
end Function

Thank you all for your answers

Sylvain Caillet







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default use vba function in formula

Hi
try
Public Function myRange(chaine As String) As Range
set myRange = Sheets("Référence").Range(chaine)
End Function


--
Regards
Frank Kabel
Frankfurt, Germany

"Sylvain" schrieb im Newsbeitrag
...
Thank you for your quick reply but i need one more information,

please.

What should be the return type of my function to be useable as

argument for
other standard functions in formulas, such as Sum, Correlation

coefficient
calculus, ... ?

I have tried the following function, but it doesn't work :

Public Function myRange(chaine As String) As Range
plage = Sheets("Référence").Range(chaine)
End Function

If i write a formula such as
=SUM(myRange("B29:B31"))
It doesn't work.

Thank you for your help !

Sylvain Caillet



"Frank Kabel" a écrit dans le message de

news:
...
Hi
if you don't declare the function as private and put it in a

standard
module you can simply use your function as you would use a

worksheet
function.
Also see
http://www.mvps.org/dmcritchie/excel/getstarted.htm

--
Regards
Frank Kabel
Frankfurt, Germany

"news.wanadoo.fr" schrieb im Newsbeitrag
...
Hi !

Is ther any way to use some vba function i wrote in my cells

formulas
??

for example : =myfunction(A1:A10)

with

function myfunction (myRange as range)
....
end Function

Thank you all for your answers

Sylvain Caillet








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default use vba function in formula

Your function can be called as any other worksheet function, exactly as you
show. AN example function is

In your function you should only look to manipulate the input data, or some
fixed worksheet data, and return a result. You should not try to amend any
worksheet/cell attributes such as the cell colour, font, it will not work.

So your function might look like as an example

Public Function AnyReds(rng As Range) As Boolean
Dim cell As Range

For Each cell In rng
If cell.Interior.ColorIndex = 3 Then
AnyReds = True
Exit Function
End If
Next
End Function

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"news.wanadoo.fr" wrote in message
...
Hi !

Is ther any way to use some vba function i wrote in my cells formulas ??

for example : =myfunction(A1:A10)

with

function myfunction (myRange as range)
....
end Function

Thank you all for your answers

Sylvain Caillet




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with function / Formula Jerry Bailey Excel Worksheet Functions 4 January 29th 09 05:09 AM
Help with OR function in IF function formula veggies27 Excel Worksheet Functions 3 March 18th 08 10:04 PM
Help with function/formula please!!! Ssuzs Excel Worksheet Functions 7 June 13th 07 08:31 AM
Function or formula Martin Excel Worksheet Functions 4 January 8th 07 05:01 PM
A formula/function to return a formula/function sith janitor Excel Worksheet Functions 4 September 22nd 06 05:01 PM


All times are GMT +1. The time now is 06:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"