Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default How can I output VBA function results (array's for example) to spreadsheet

I write custom functions that often collect data from an excel
spreadsheet in the open workbook, do a bunch of other calcs with the
data, and return a 2-d array results. The problem is that I want to
output the array results to some new or existing spreadsheet in the
workbook but don't want to use use array formula's (i.e.
Ctrl-Shift-Enter) to place the resulting output result where the array
formula's entered.

In past I've used a work-around by putting all the functions that
return results I want to put into the spreadsheet under a sub(), then
call another sub() to display results in the worksheet of interest by
looping thru the appropriate rows/col's (ie. Cells(r,c).value = x(i)).


But isn't there a way to get the results to be displayed in the
appropriate worksheet cells I chose from within a function() instead of
having to go put everything under a sub()?

For example, the following doesn't work to get data placed in the
requested cells (or anywhere on a the active spreadsheet).

e.g. Assume data is 1-d array of unknown number of elements
function output(data as variant)

dim cnt as integer, i as integer, r as integer c as integer
cnt = Ubound(data)
'assume r & c are given initial values from functions rowstart() &
colstart() that finds someplace on the spreadsheet of interest to start
placing the data.
r = rowstart()
c = colstart()

'place data in column c
for i = 0 to cnt-1
Cells(r,c).value = data(i)
r=r+1
next i

End function

On the other hand, if I replace function routine output(data as
variant) with sub routine sub(data as variant) everything works just
fine.

Is there something I have to put into or call from within the function
to get it to work as I'd like or what am I missing?

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 93
Default How can I output VBA function results (array's for example) to spreadsheet

That looks to be fine as long as R and C are valid and the array was set-up
properly. You do need to give sheet names somewhere, i'm assuming you have
this function in a module.
This is how I did it, I don't like names like data either, it will be bad
too often.
For i = 0 To cnt - 1
Cells(r, c) = myData(i, 1)
r = r + 1
Next

--
--
-John
Please rate when your question is answered to help us and others know what
is helpful.

wrote in message
oups.com...
I write custom functions that often collect data from an excel
spreadsheet in the open workbook, do a bunch of other calcs with the
data, and return a 2-d array results. The problem is that I want to
output the array results to some new or existing spreadsheet in the
workbook but don't want to use use array formula's (i.e.
Ctrl-Shift-Enter) to place the resulting output result where the array
formula's entered.

In past I've used a work-around by putting all the functions that
return results I want to put into the spreadsheet under a sub(), then
call another sub() to display results in the worksheet of interest by
looping thru the appropriate rows/col's (ie. Cells(r,c).value = x(i)).


But isn't there a way to get the results to be displayed in the
appropriate worksheet cells I chose from within a function() instead of
having to go put everything under a sub()?

For example, the following doesn't work to get data placed in the
requested cells (or anywhere on a the active spreadsheet).

e.g. Assume data is 1-d array of unknown number of elements
function output(data as variant)

dim cnt as integer, i as integer, r as integer c as integer
cnt = Ubound(data)
'assume r & c are given initial values from functions rowstart() &
colstart() that finds someplace on the spreadsheet of interest to start
placing the data.
r = rowstart()
c = colstart()

'place data in column c
for i = 0 to cnt-1
Cells(r,c).value = data(i)
r=r+1
next i

End function

On the other hand, if I replace function routine output(data as
variant) with sub routine sub(data as variant) everything works just
fine.

Is there something I have to put into or call from within the function
to get it to work as I'd like or what am I missing?



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default How can I output VBA function results (array's for example) to spreadsheet

John, is your sample code in function or sub?
John Bundy wrote:
That looks to be fine as long as R and C are valid and the array was set-up
properly. You do need to give sheet names somewhere, i'm assuming you have
this function in a module.
This is how I did it, I don't like names like data either, it will be bad
too often.
For i = 0 To cnt - 1
Cells(r, c) = myData(i, 1)
r = r + 1
Next

--
--
-John
Please rate when your question is answered to help us and others know what
is helpful.

wrote in message
oups.com...
I write custom functions that often collect data from an excel
spreadsheet in the open workbook, do a bunch of other calcs with the
data, and return a 2-d array results. The problem is that I want to
output the array results to some new or existing spreadsheet in the
workbook but don't want to use use array formula's (i.e.
Ctrl-Shift-Enter) to place the resulting output result where the array
formula's entered.

In past I've used a work-around by putting all the functions that
return results I want to put into the spreadsheet under a sub(), then
call another sub() to display results in the worksheet of interest by
looping thru the appropriate rows/col's (ie. Cells(r,c).value = x(i)).


But isn't there a way to get the results to be displayed in the
appropriate worksheet cells I chose from within a function() instead of
having to go put everything under a sub()?

For example, the following doesn't work to get data placed in the
requested cells (or anywhere on a the active spreadsheet).

e.g. Assume data is 1-d array of unknown number of elements
function output(data as variant)

dim cnt as integer, i as integer, r as integer c as integer
cnt = Ubound(data)
'assume r & c are given initial values from functions rowstart() &
colstart() that finds someplace on the spreadsheet of interest to start
placing the data.
r = rowstart()
c = colstart()

'place data in column c
for i = 0 to cnt-1
Cells(r,c).value = data(i)
r=r+1
next i

End function

On the other hand, if I replace function routine output(data as
variant) with sub routine sub(data as variant) everything works just
fine.

Is there something I have to put into or call from within the function
to get it to work as I'd like or what am I missing?


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
Working spreadsheet highlighting function for Excel 2007 Mr. Low Excel Worksheet Functions 4 June 16th 06 06:12 PM
numerical integration integreat Excel Discussion (Misc queries) 4 May 12th 06 02:40 AM
URGENT: Function Results in Fractions danjones Excel Discussion (Misc queries) 3 April 15th 06 12:11 AM
CountIF Function On Linked Spreadsheet Josh in Indy Excel Discussion (Misc queries) 0 April 5th 06 05:09 PM
spreadsheet function Excel GuRu Excel Discussion (Misc queries) 2 January 6th 05 04:09 AM


All times are GMT +1. The time now is 07:21 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"