×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

return of function values in Excel
2

return of function values in Excel

return of function values in Excel

(OP)
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?

RE: return of function values in Excel

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...

RE: return of function values in Excel

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.

RE: return of function values in Excel

2
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:

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 =test() and press Ctrl-Shift-Enter.


RE: return of function values in Excel

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
http://www.xcalcs.com
Online tools for structural design

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources