workbook event, only to certain sheets
What about ranges? How can I make that the event should only work in a
certain range?
"Tom Hutchins" wrote:
Maybe something like
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target
As Range, Cancel As Boolean)
Dim x As Long
For x = 1 To Sheets.Count
If Sheets(x).Name = Sh.Name Then
Select Case x
Case 3, 5, 7 'skip these sheets
Exit For
Case Else
'your event code
End Select
End If
Next x
End Sub
Hope this helps,
Hutch
"art" wrote:
Thanks, it works great, however, how can I make that I should not need to
enter the "Name" of the sheet, rather I should enter which sheet number it
is. Like worksheet(1)...
Thanks.
"Tom Hutchins" wrote:
The events you mentioned apply to the ThisWorkbook module. Just check the
name of the sheet from which the event was called. If it is one of the sheets
where you don't want the code to work, exit the sub.
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target
As Range, Cancel As Boolean)
Select Case Sh.Name
Case "NotThisSheet1", "NotThisSheet2", "NotThisSheet3"
Exit Sub
Case Else
'do your event code
End Select
End Sub
Hope this helps,
Hutch
"art" wrote:
Hello:
I have a Workbook_SheetBeforeDoubleClick and Workbook_SheetBeforeRightClick
event that does certain things when triggered. How ever, I need this event to
apply only to certain sheets. I have about 20 sheets, and I don't want to put
it in each sheet seperatly. Is there a way to force the workbook event to
kick in only for specific sheets?
Also, I need the event to apply only to a certain range in the sheet. How
can I apply that as well to the code?
Please help me figure this out.
Thanks for your help.
|