Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

return of function values in Excel 2

Status
Not open for further replies.

engped

Electrical
Nov 9, 2001
2
I would like to know if it is possible to get 2 or 3 values from the same function that was generated in the VBA Editor from Excel.
If it is, how could i do it?
 
Replies continue below

Recommended for you

where do you want the values to end up? If you're using your function from within a cell in a spreadsheet, then I think you'll pretty much be stuck getting your results in that cell. You can combine all the values into a string using the format function, and put that string in your cell...
 
You could also use a subroutine to fill in as many cells as you want. Like ivymike suggested, you should probably post a bit more detail about your problem. DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
This is a good one, engped!
Your function should return an array of values, so it's going to be an array function. For example:
Code:
Public Function test() As Variant
    test = Array(1, 2, 3)
End Function
To retrieve the test values in the spreadsheet select cells
A1:C1, then type
Code:
=test()
and press Ctrl-Shift-Enter.


 
yakpol's advice is the correct one if you want to return values into an array of cells of an Excel sheet.
If you stay within VB, the correct way for returning multiple values is to declare the function as returning a user defined type (a 'structure').
prex
motori@xcalcsREMOVE.com
Online tools for structural design
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor