Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Using a Sub instead of a Function

Status
Not open for further replies.

maloneb

Mechanical
Joined
Aug 11, 2011
Messages
22
Location
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

 
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
 
Can you post both versions of the code?
 
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.

Part and Inventory Search

Sponsor

Back
Top