Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Using a Sub instead of a Function

Status
Not open for further replies.

maloneb

Mechanical
Aug 11, 2011
22
0
0
GB
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

 
Replies continue below

Recommended for you

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
 
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
 
Status
Not open for further replies.
Back
Top