Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default What is a Sub

A sub is a set of instructions used to perform an action. In theory you
should try to write your subs to do one thing. For example you could write a
sub to format a sheet of data, or the sub could protect all of the sheets in
a workbook. When your subs start doing too many things they become very
difficult to debug.

A function on the other hand returns a value. In theory a function should
avoid having side effect such as changing any of the data that it is
accessing. For example Sum is a function which returns the total of all of
the numbers that are passed into it. It does not change any of the numbers
that are passed into it as that would be an unwanted side effect.

Very often your subs will call functions in order to perform the actions
that they must do, but rarely will a function call a sub, as the sub would
produce a side effect.
--
HTH...

Jim Thomlinson


"Abode" wrote:

Im very new to Excel and I've found the ability to program functions very
useful and a good way to give me a break from working while still working. I
see many people here asking questions and getting answers with code that
seems to be a 'sub'. I'd love to start learning how to program them but I
dont know how to implement them into Excel and why they are more useful than
functions (other than the ability to obviously be far more complex) Oddly
enough I didn't quite see this question being asked anywhere. Thank you for
your time

Mark

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"