Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default workbook event, only to certain sheets

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default workbook event, only to certain sheets

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default workbook event, only to certain sheets

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default workbook event, only to certain sheets

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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default 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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default workbook event, only to certain sheets

What about ranges? How can I make that the event should only work in a
certain range?


You can't restrict an event to trigger for only a range of cells. You
can, however, test the Target parameter, which is a reference to the
cell that initiated the event. If Target is within some range, run
your code. Otherwise, don't run the code. For example, the following
code shows how to restrict BeforeDoubleClick to take action only if
the user double-clicks somewhere within A1:A10.


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Not Application.Intersect(Target, _
Me.Range("A1:A10")) Is Nothing Then
'''''''''''''''''''''''''''''
' your event code goes here
'''''''''''''''''''''''''''''
End If
End Sub


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Sun, 16 Nov 2008 10:33:00 -0800, art
wrote:

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.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default workbook event, only to certain sheets

Private Sub Workbook_SheetBeforeDoubleClick(ByVal _
Sh As Object, ByVal Target As Range, Cancel As Boolean)
Const MY_RANGE As String = "A1:A10" 'adjust to suit
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
If Not Intersect(Target, ActiveSheet.Range(MY_RANGE)) Is Nothing Then
MsgBox "you have d-clicked on " & ActiveCell.Address
Cancel = True
End If
End Select
End If
Next x
End Sub


Gord Dibben MS Excel MVP


On Sun, 16 Nov 2008 10:33:00 -0800, art
wrote:

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.


  #8   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default workbook event, only to certain sheets

I have a named range "GridCell". How can I restict it only to that range?



"Chip Pearson" wrote:

What about ranges? How can I make that the event should only work in a
certain range?


You can't restrict an event to trigger for only a range of cells. You
can, however, test the Target parameter, which is a reference to the
cell that initiated the event. If Target is within some range, run
your code. Otherwise, don't run the code. For example, the following
code shows how to restrict BeforeDoubleClick to take action only if
the user double-clicks somewhere within A1:A10.


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Not Application.Intersect(Target, _
Me.Range("A1:A10")) Is Nothing Then
'''''''''''''''''''''''''''''
' your event code goes here
'''''''''''''''''''''''''''''
End If
End Sub


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Sun, 16 Nov 2008 10:33:00 -0800, art
wrote:

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.


  #9   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default workbook event, only to certain sheets

There is a error saying method or data member not found?

"Chip Pearson" wrote:

What about ranges? How can I make that the event should only work in a
certain range?


You can't restrict an event to trigger for only a range of cells. You
can, however, test the Target parameter, which is a reference to the
cell that initiated the event. If Target is within some range, run
your code. Otherwise, don't run the code. For example, the following
code shows how to restrict BeforeDoubleClick to take action only if
the user double-clicks somewhere within A1:A10.


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Not Application.Intersect(Target, _
Me.Range("A1:A10")) Is Nothing Then
'''''''''''''''''''''''''''''
' your event code goes here
'''''''''''''''''''''''''''''
End If
End Sub


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Sun, 16 Nov 2008 10:33:00 -0800, art
wrote:

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.


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default workbook event, only to certain sheets


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Not Application.Intersect(Target, _
Range("GridCell")) Is Nothing Then
''''''''''''''''''''''''''''''''''
' do your double-click code here
'''''''''''''''''''''''''''''''''
Cancel = True
End If
End Sub

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sun, 16 Nov 2008 15:53:00 -0800, art
wrote:

I have a named range "GridCell". How can I restict it only to that range?



"Chip Pearson" wrote:

What about ranges? How can I make that the event should only work in a
certain range?


You can't restrict an event to trigger for only a range of cells. You
can, however, test the Target parameter, which is a reference to the
cell that initiated the event. If Target is within some range, run
your code. Otherwise, don't run the code. For example, the following
code shows how to restrict BeforeDoubleClick to take action only if
the user double-clicks somewhere within A1:A10.


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Not Application.Intersect(Target, _
Me.Range("A1:A10")) Is Nothing Then
'''''''''''''''''''''''''''''
' your event code goes here
'''''''''''''''''''''''''''''
End If
End Sub


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Sun, 16 Nov 2008 10:33:00 -0800, art
wrote:

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.




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default workbook event, only to certain sheets



What exactly does the error message say (details count) and on what
line of code does execution terminate (that line will be highlighted
in yellow)?

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Sun, 16 Nov 2008 16:13:01 -0800, art
wrote:

There is a error saying method or data member not found?

"Chip Pearson" wrote:

What about ranges? How can I make that the event should only work in a
certain range?


You can't restrict an event to trigger for only a range of cells. You
can, however, test the Target parameter, which is a reference to the
cell that initiated the event. If Target is within some range, run
your code. Otherwise, don't run the code. For example, the following
code shows how to restrict BeforeDoubleClick to take action only if
the user double-clicks somewhere within A1:A10.


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Not Application.Intersect(Target, _
Me.Range("A1:A10")) Is Nothing Then
'''''''''''''''''''''''''''''
' your event code goes here
'''''''''''''''''''''''''''''
End If
End Sub


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Sun, 16 Nov 2008 10:33:00 -0800, art
wrote:

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.


  #12   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default workbook event, only to certain sheets

thanks it works now. One more thing. The range gridcell was named for cell in
sheet1, however I want the named range to apply to all sheets, how can I do
this?



"Chip Pearson" wrote:


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Not Application.Intersect(Target, _
Range("GridCell")) Is Nothing Then
''''''''''''''''''''''''''''''''''
' do your double-click code here
'''''''''''''''''''''''''''''''''
Cancel = True
End If
End Sub

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sun, 16 Nov 2008 15:53:00 -0800, art
wrote:

I have a named range "GridCell". How can I restict it only to that range?



"Chip Pearson" wrote:

What about ranges? How can I make that the event should only work in a
certain range?

You can't restrict an event to trigger for only a range of cells. You
can, however, test the Target parameter, which is a reference to the
cell that initiated the event. If Target is within some range, run
your code. Otherwise, don't run the code. For example, the following
code shows how to restrict BeforeDoubleClick to take action only if
the user double-clicks somewhere within A1:A10.


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Not Application.Intersect(Target, _
Me.Range("A1:A10")) Is Nothing Then
'''''''''''''''''''''''''''''
' your event code goes here
'''''''''''''''''''''''''''''
End If
End Sub


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Sun, 16 Nov 2008 10:33:00 -0800, art
wrote:

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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Sheets (Need to create 500 individual sheets in one workbook, pulling DATA Amaxwell Excel Worksheet Functions 4 August 17th 06 06:23 AM
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Worksheet Functions 6 March 29th 06 12:43 PM
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Programming 6 March 29th 06 12:43 PM
Macro for filter on protected workbook that works for all sheets, no matter what sheets are named? StargateFanFromWork[_3_] Excel Programming 6 January 26th 06 06:31 PM
Same event, multiple sheets? Robert Smith Excel Discussion (Misc queries) 1 December 24th 04 11:36 AM


All times are GMT +1. The time now is 12:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"