BeforeDoubleClick inc 5 named ranges

L7B

New Member
Joined
Aug 23, 2011
Messages
6
Hi

I can get this to work with 2 named ranges but as I add the others it stops working.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Call Create_Shape_CLOSE_KPI_DEFINITION

    If Not Intersect(Target, Range("Employee_Performance_Plans")) Is Nothing Then
Call Show_EmployeePerformancePlans
End If
 
    If Intersect(Target, Range("Employee_Engagement")) Is Nothing Then Exit Sub
Call Show_ENGAGEMENT
Else
  
  If Intersect(Target, Range("Performance_Reviews_Completion")) Is Nothing Then Exit Sub
Call Show_PerformanceReviewsCompletion
Else
    If Intersect(Target, Range("Employee_Turnover")) Is Nothing Then Exit Sub
Call Show_EmployeeTurnover
Else
    If Intersect(Target, Range("Absenteeism_")) Is Nothing Then Exit Sub
Call Show_Absenteeism
End If
End Sub

Thanks for the help
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Difficult to test with all the named ranges and calls to other procedures that are not posted, but the "Exit Sub" statements are preventing it from ever evaluating the lines near the bottom. As soon as the second test evaluates to "Nothing" it exits the sub and it never has a chance to test the rest of the conditions/intersections. I assume that is what you mean by you can only make it work with 2 named ranges.

Not sure what's going on with the all the Ifs, End Ifs, Else etc. Looks like you need some serious restructuring and/or ElseIfs in there.

Maybe try the sample below and/or provide a better description of exactly what you're trying to do.

Gary

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Call Create_Shape_CLOSE_KPI_DEFINITION

'Could possibly "Union" all 5 named ranges and exit if there is no intersection with target instead of individual Exit Subs

If Not Application.Intersect(Target, Range("Employee_Performance_Plans")) Is Nothing Then
    Call Show_EmployeePerformancePlans
    Exit Sub 'Maybe not needed if named ranges don't overlap
End If

If Not Application.Intersect(Target, Range("Employee_Engagement")) Is Nothing Then
    Call Show_ENGAGEMENT
    Exit Sub 'Maybe not needed if named ranges don't overlap
End If

If Not Application.Intersect(Target, Range("Performance_Reviews_Completion")) Is Nothing Then
    Call Show_PerformanceReviewsCompletion
    Exit Sub 'Maybe not needed if named ranges don't overlap
End If

If Not Application.Intersect(Target, Range("Employee_Turnover")) Is Nothing Then
    Call Show_EmployeeTurnover
    Exit Sub 'Maybe not needed if named ranges don't overlap
End If

If Not Application.Intersect(Target, Range("Absenteeism_")) Is Nothing Then
    Call Show_Absenteeism
    Exit Sub 'Maybe not needed if named ranges don't overlap
End If

End Sub
 
Upvote 0
Hi Lee,

Here's a sample. I believe Union will accept up to 30 ranges as arguments.

Gary

Code:
Public Sub Test()

'Union 4 ranges named "E","G","I" & "Row1" change range names to suit

Dim oUnion As Range

Set oUnion = Union(ActiveSheet.Range("E"), ActiveSheet.Range("G"), ActiveSheet.Range("I"), ActiveSheet.Range("Row1"))

oUnion.Interior.ColorIndex = 3

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

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