PC Review


Reply
Thread Tools Rate Thread

Create VBA function that returns many values

 
 
gkk-vba
Guest
Posts: n/a
 
      18th Jan 2008
I would like to write a VBA function that takes as input real numbers and
returns more than one value in distinct cells of the worksheet, whose
location can vary dynamically.Specifically I would like a function which
does domething like this.
Function F(x as Double, y as Double, z as Double)
.... some code here
F in one cell of the worksheet
G in another cell etc.
End Function
Any help will be appreciated
 
Reply With Quote
 
 
 
 
Niek Otten
Guest
Posts: n/a
 
      18th Jan 2008
Although there are some cases where multiple cells can be populated (array functions), what you require is not possible and even
more, not desirable.
Consider a function here as a function in math; the only thing it can do is replace its call with a value.
Technically there are no problems to let a function change several locations (and, in VBA, you can indeed (under certain
circumstances) change variables that are not in the argument list of the call), but, fortunately, in Excel worksheets, functions
follow very much the patterns of math functions. So you can't change anything in a workbook, you can just return a value which
will take the place of the call to the function.

If this doesn't satisfy your requirements, please elaborate a bit on what you're trying to achieve.

--
Kind regards,

Niek Otten
Microsoft MVP - Excel


"gkk-vba" <gkk-(E-Mail Removed)> wrote in message news:318DC945-DB20-43BC-A9EB-(E-Mail Removed)...
|I would like to write a VBA function that takes as input real numbers and
| returns more than one value in distinct cells of the worksheet, whose
| location can vary dynamically.Specifically I would like a function which
| does domething like this.
| Function F(x as Double, y as Double, z as Double)
| ... some code here
| F in one cell of the worksheet
| G in another cell etc.
| End Function
| Any help will be appreciated


 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      19th Jan 2008
A function can only return values to the cell(s) from which it was called.
If the function is entered into an array of cells, it can return an array to
those cells. See http://www.cpearson.com/Excel/Return...ysFromVBA.aspx
for details and example code.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


"gkk-vba" <gkk-(E-Mail Removed)> wrote in message
news:318DC945-DB20-43BC-A9EB-(E-Mail Removed)...
>I would like to write a VBA function that takes as input real numbers and
> returns more than one value in distinct cells of the worksheet, whose
> location can vary dynamically.Specifically I would like a function which
> does domething like this.
> Function F(x as Double, y as Double, z as Double)
> ... some code here
> F in one cell of the worksheet
> G in another cell etc.
> End Function
> Any help will be appreciated


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array function that returns values within several intervals Hjuler Microsoft Excel Worksheet Functions 6 23rd Sep 2008 04:11 PM
Trying to create a requisition form that returns values =?Utf-8?B?VGltNDEwNA==?= Microsoft Excel Discussion 2 30th Oct 2007 10:51 AM
Function returns two values Brian Cahill Microsoft VB .NET 4 31st Mar 2006 04:09 PM
Function returns two values Brian Cahill Microsoft Dot NET 5 31st Mar 2006 04:07 PM
Excel PMT function returns incorrect values =?Utf-8?B?dnNzajE=?= Microsoft Excel Worksheet Functions 2 25th Sep 2004 03:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:35 AM.