Using Parameters/Arguments with Subs and Functions RRS feed

  • Question

  • Hi,

    I have read a lot about parameters and arguments included in the brackets of a Sub or Function(etc...), but still have little idea of when and why you would use them. Instead of declaring variables with Dim? And why are they more popular to use with Functions than with Subs.....?

    Someone give me an answer that a 10 year old would understand?

    Thanks all.


    Thursday, January 10, 2013 4:19 PM

All replies

  • Functions and Subs can be designed to be more reusable, and when you pass values to them, you make them more flexible, allowing different values and objects to be used. Subs can change almost anything in Excel, but Functions cannot, only modifying the value of the cell that calls it. Functions are written more frequently with parameters and arguments because then they are usable as worksheet functions and get recacled with the recalc tree. Subs get written with parameters and arguments too - that is usually a little more advanced usage, but then the sub must be run from another sub that does not have parameters and arguments.  Usually, people leave them off because subs often written to do very specific tasks and then it makes less sense to parameterize them.

    Thursday, January 10, 2013 4:35 PM