Thread: Sub vs Function
View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default Sub vs Function

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