Reputation: 134
I have a workbook i am working on where one page has the need for multiple buttons. However, i have chosen to use the beforerightclick
on set cells instead as this fits the sheet and the users better.
I have several beforerightclick
rules that work fine. My issue is that the user can no longer right click anywhere else in that sheet.
I found an example on another website that does allow the right click to work, however, it doesnt allow multiple targets with their own rules. Unless i have missed something, which could be the case think this is week 3 in doing VBA.
Here is my code: -
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address = "$A$13" Then
If Range("B12") = "Yes" Then
Call Item_1_Get_Data
End If
If Range("C12") = "Yes" Then
Call Item_2_Get_Data
End If
If Range("D12") = "Yes" Then
Call Item_3_Get_Data
End If
If Range("E12") = "Yes" Then
Call Item_4_Get_Data
End If
If Range("F12") = "Yes" Then
Call Item_5_Get_Data
End If
End If
If Target.Address = "$B$13" Then
Call Item_1_Get_Data
End If
If Target.Address = "$C$13" Then
Call Item_2_Get_Data
End If
If Target.Address = "$D$13" Then
Call Item_3_Get_Data
End If
If Target.Address = "$E$13" Then
Call Item_4_Get_Data
End If
If Target.Address = "$F$13" Then
Call Item_5_Get_Data
End If
If Target.Address = "$B$10" Then
Call SimpleVersion
End If
If Target.Address = "$C$10" Then
Call DetailedVersion
End If
Cancel = True
End Sub
This is what i have found, but i cant get this to work with all the different right click criteria i have set. I am obviously missing something. Any ideas?
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("A1:B3")) Is Nothing Then Exit Sub
Cancel = True
'
'your code here
'
End Sub
If i used intersect(target, Range(A13,B13,C13,D13,E13,F13,B10,C10))
i believe i can only have one rule on this right click.
If i do multiples of intersect(target,Range(a13)
then say intersect(target,Range(B13)
it works on the first but not the second or anymore.
Thank you,
Upvotes: 0
Views: 434
Reputation: 96753
Just remove:
Cancel = True
this will allow normal right-click behavior for "normal" cells.
Upvotes: 1