PDA

View Full Version : Solved: Events



Opv
07-24-2010, 02:50 PM
When including more than one of either the Worksheet_Change, Worksheet_SelectionChange or Worksheet_BeforeDoubleClick event, are there any issues to consider as to whether they are all placed within a single Private Sub or in separate subs? Is there any advantage with one option over the other?

Bob Phillips
07-24-2010, 04:16 PM
Of course, you place them in the code module of the worksheet that they apply to.

Opv
07-24-2010, 04:19 PM
Of course, you place them in the code module of the worksheet that they apply to.
Thanks, but that is not my question. My question is whether it is better to place all the worksheet_beforeafterclick (or worksheet_change or worksheet_selectionchange) scripts in one sub or individual subs. Does it matter if they are all in one or individual subs?

P.S. I know each type goes in its own sub. I'm asking about groups of like scripts.

GTO
07-24-2010, 06:24 PM
What do you mean by "in one sub"?

If you are asking whether this:

Private Sub Worksheet_Change(ByVal Target As Range)
Call DoThis
Call DoThat
End Sub

or

Private Sub Worksheet_Change(ByVal Target As Range)
Call DoThis
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Call DoThat
End Sub

Then go with the first one as the latter will fail. You cannot have two same-named procedures in the same module.

Opv
07-24-2010, 06:31 PM
What do you mean by "in one sub"?
Sorry for the confusion.... I mean:


Private Sub Worksheet_BeforeDoubleClick(ByVal Target as Range)
'do first BeforeDoubleClick thing here

'do second BeforeDoubleClick thing here

'etc., etc.


OR


Private Sub Worksheet_BeforeDoubleClick(ByVal Target as Range)
'do first BeforeDoubleClick thing here






Private Sub Worksheet_BeforeDoubleClick(ByVal Target as Range)
'
'do second BeforeDoubleClick thing here

'etc., etc.

Opv
07-24-2010, 06:42 PM
Then go with the first one as the latter will fail. You cannot have two same-named procedures in the same module.

Thanks. I appreciate the help.