Compile error message

mmdmalta

New Member
Joined
Oct 9, 2006
Messages
40
hello, I used a VCA formula in my spread sheet. I want to do the exact same thing, but in a different area of the spread sheet. This is the formula i used and it worked in one area, but not the other.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("b12:f12")) Is Nothing Then
Cancel = True
Target.Interior.Color = vbYellow
End If
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("b12:f12")) Is Nothing Then
Cancel = True
Target.Interior.Color = Cancel = False
Target.Interior.Color = vbWhite
End If
End Sub

The second area with the range B12:f12, pops up a window that i have a compile errpr" Ambiguous name detected: Worksheet) BeforeDoubleClick. Can you tell me what i need to do with this second area inside the VBA code?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Something like
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("b12:f12")) Is Nothing Then
   Cancel = True
   Target.Interior.Color = vbYellow
ElseIf Not Intersect(Target, Range("H12:K12")) Is Nothing Then
   Cancel = True
   Target.Interior.Color = vbYellow
End If
End Sub
 
Upvote 0
Something like
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("b12:f12")) Is Nothing Then
   Cancel = True
   Target.Interior.Color = vbYellow
ElseIf Not Intersect(Target, Range("H12:K12")) Is Nothing Then
   Cancel = True
   Target.Interior.Color = vbYellow
End If
End Sub
 
Upvote 0
thank you, but that didn't work. The cell are different the first one references different cells, but even when i changed the cells it tells me it's ambiguous.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A41:E43")) Is Nothing Then
Cancel = True
Target.Interior.Color = vbYellow
End If
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A41:E43")) Is Nothing Then
Cancel = True
Target.Interior.Color = Cancel = False
Target.Interior.Color = vbWhite
End If
End Sub
 
Upvote 0
Do you have any other code in that sheet module?
You can only have one instance of an event in any sheet.
 
Upvote 0
Yes, i do. But I assume there has to be another way to be able to do it elsewhere in the document. Is there a way to do that? Here is my code for the one section. All i want to do is add it to Cells B12 through F12.

Private Sub CheckBox1_Click()

End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A41:E43")) Is Nothing Then
Cancel = True
Target.Interior.Color = vbYellow
End If
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A41:E43")) Is Nothing Then
Cancel = True
Target.Interior.Color = Cancel = False
Target.Interior.Color = vbWhite
End If
End Sub
 
Upvote 0
Then replace
Code:
Range("H12:K12"))
in the example I supplied with
Code:
Range("A41:E43")
& you can do the RightClick event in the same way
 
Upvote 0
ok, that half worked! It's doing it in the other cells, but now, when i right click the color yelllow doesn't go back to the original cell color in both sections...there is still something i'm missing.
 
Upvote 0
Have you changed the right click event? If so can you post the modified code.
 
Upvote 0
yes, here it is:

Private Sub CheckBox1_Click()

End Sub

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("b12:f12")) Is Nothing Then
   Cancel = True
   Target.Interior.Color = vbYellow
ElseIf Not Intersect(Target, Range("a43:E45")) Is Nothing Then
   Cancel = True
   Target.Interior.Color = vbYellow
End If
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("b12:f12")) Is Nothing Then
   Cancel = True
   Target.Interior.Color = vbYellow
ElseIf Not Intersect(Target, Range("a43:E45")) Is Nothing Then
   Cancel = True
   Target.Interior.Color = vbYellow
End If
End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,308
Members
449,151
Latest member
JOOJ

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top