Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Rob
A sub is simply a function returning Void, nothing, as you know. So there are no differences from a programming view. In Excel, however, you'll find Subs in the Tools Macro Start menu, and you also can assign them to buttons and objects. Not so with funtions, you can't run them outside the VBE unless they are called from a Sub. Functions can be used directly in spreadsheet cells -where they, as Frank points out, loose their "macro power". -- HTH. Best wishes Harald Followup to newsgroup only please "Rob van Gelder" skrev i melding ... Something that I've always been curious about, but never found a real reason behind. Why do we use a Sub instead of using a Function? Is there any reason other than a Sub returns nothing? These both do exactly the same thing: Function Test() MsgBox "test" End Function Sub Test() MsgBox "test" End Sub At the moment my opinion is that Sub is redundant and may as well never be used. Thoughts? Comments? -- Rob van Gelder - http://www.vangelder.co.nz/excel |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
There is another "advantage"; you can view all your function names in the
function wizard if you don't make them private. -- Regards, Tom Ogilvy "Harald Staff" wrote in message ... Hi Rob A sub is simply a function returning Void, nothing, as you know. So there are no differences from a programming view. In Excel, however, you'll find Subs in the Tools Macro Start menu, and you also can assign them to buttons and objects. Not so with funtions, you can't run them outside the VBE unless they are called from a Sub. Functions can be used directly in spreadsheet cells -where they, as Frank points out, loose their "macro power". -- HTH. Best wishes Harald Followup to newsgroup only please "Rob van Gelder" skrev i melding ... Something that I've always been curious about, but never found a real reason behind. Why do we use a Sub instead of using a Function? Is there any reason other than a Sub returns nothing? These both do exactly the same thing: Function Test() MsgBox "test" End Function Sub Test() MsgBox "test" End Sub At the moment my opinion is that Sub is redundant and may as well never be used. Thoughts? Comments? -- Rob van Gelder - http://www.vangelder.co.nz/excel |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
copy of excel file not showing formulal/function in the function b | Excel Discussion (Misc queries) | |||
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) | Excel Worksheet Functions | |||
Offset function with nested match function not finding host ss. | Excel Worksheet Functions | |||
Emulate Index/Match combo function w/ VBA custom function | Excel Worksheet Functions | |||
Adding a custom function to the default excel function list | Excel Programming |