×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

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!

*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

Using a Sub instead of a Function

Using a Sub instead of a Function

Using a Sub instead of a Function

(OP)
Hey guys,

I've got a Sub-routine that filters a table and performs a lookup selecting the appropriate data.  

The Sub-routine was originally a function, yet the function was not working correctly.  

My question is, why does the code run correctly when it is a sub-routine and not a function?  And how do you apply a sub routine on one cell in excell to be used instead of a function?

Thanks

 

RE: Using a Sub instead of a Function

I think you could call a function with that function calling a sub.

I don't see much difference in calling a sub or a function, other than the way in which the arguments are passed and the return value is defined in a function.

Are all argument variables defined correctly according to their variable type?

We are more connected to everyone in the world than we've ever been before, except to the person sitting next to us.  Lisa Gansky

RE: Using a Sub instead of a Function

Can you post both versions of the code?

RE: Using a Sub instead of a Function

Quote:

My question is, why does the code run correctly when it is a sub-routine and not a function?

It's a bit hard to say without seeing the code.  If the sub writes values back to the spreadsheet at any stage it won't work as a function, so that's the most likely reason.  There are some things that are a sort of "virtual write" which won't work in functions as well.

You can tie a sub to a worksheetchange event to get it working much like a UDF.

 

Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
 

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! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close