BeforeDoubleClick

Rob1972

New Member
Joined
May 19, 2018
Messages
9
I have a spreadsheet in which I want to perform a BeforeDoubleClick command on. I have two ranges which are M3 to M49 (range 1) and M50 to M250 (Range2). In range one when i perform a doubleclick I want the contents of the cell to change from "NOT CHECKED" to "CHECKED" and the cell colour to change from red to green (this command already works), the problem arises with the second range, which I want it to do the same as the first range but in this case I also want it to hide the entire row. I have managed to write the code for these to work independently my difficulty is getting them to work together.

The code I have so far is:

Code:
 Private Sub Worksheet_BeforeDoubleclick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("$M$3:$M$49")) Is Nothing Then Exit Sub
    Select Case Target
    Case "NOT CHECKED"
        Target = "CHECKED"
        Target.Interior.ColorIndex = 4
    Case Else
        Target = "NOT CHECKED"
        Target.Interior.ColorIndex = 3
If Intersect(Target, Range("$M$50:$M$250")) Is Nothing Then Exit Sub
    Select Case Target
    Case "NOT CHECKED"
        Target = "CHECKED"
        Target.Interior.ColorIndex = 4
        Target.EntireRow.Hidden = True
    Case Else
        Target = "NOT CHECKED"
        Target.Interior.ColorIndex = 3
    End Select
  End Select
End Sub
Any guidance would be gratefully appreciated.

My thanks in advance
 
Last edited by a moderator:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Can you not do a check on the range being double clicked

IE

If Target, Range("$M$3:$M$49") then
do one task
elseif
Target, Range("$M$50:$M$250") then
do another task
endif
 
Upvote 0
'Hope this makes it clearer

Code:
Private Sub Worksheet_BeforeDoubleclick(ByVal Target As Range, Cancel As Boolean)
'This will run for range "$M$3:$M$49" if it is not empty it will run the code
'then check range "$M$50:$M$250".
If Intersect(Target, Range("$M$3:$M$49")) Is Not Nothing Then
    Select Case Target
    Case "NOT CHECKED"
        Target = "CHECKED"
        Target.Interior.ColorIndex = 4
    Case Else
        Target = "NOT CHECKED"
        Target.Interior.ColorIndex = 3
    End Select
    If Intersect(Target, Range("$M$50:$M$250")) Is Not Nothing Then
        Select Case Target
        Case "NOT CHECKED"
            Target = "CHECKED"
            Target.Interior.ColorIndex = 4
            Target.EntireRow.Hidden = True
        Case Else
            Target = "NOT CHECKED"
            Target.Interior.ColorIndex = 3
        End Select
    End If
End If
End Sub
 
Last edited:
Upvote 0
FYI, you have to use:

Code:
If Not Intersect(Target, Range("$M$3:$M$49")) Is Nothing Then

rather than:

Code:
If Intersect(Target, Range("$M$3:$M$49")) Is Not Nothing Then
 
Last edited:
Upvote 0
Thank you to you both, the code for the first range is working perfectly however the secoond range still doesn't work
 
Upvote 0
What's your current code and what does "doesn't work" mean? Errors / does nothing / does wrong thing?
 
Upvote 0
Does it have to work independent of the first range?

If so do
Code:
Private Sub Worksheet_BeforeDoubleclick(ByVal Target As Range, Cancel As Boolean)
'This will run for range "$M$3:$M$49" if it is not empty it will run the code
'then check range "$M$50:$M$250".
If Not Intersect(Target, Range("$M$3:$M$49")) Is Nothing Then
    Select Case Target
    Case "NOT CHECKED"
        Target = "CHECKED"
        Target.Interior.ColorIndex = 4
    Case Else
        Target = "NOT CHECKED"
        Target.Interior.ColorIndex = 3
    End Select
End If
If Not Intersect(Target, Range("$M$50:$M$250")) Is Nothing Then
     Select Case Target
     Case "NOT CHECKED"
         Target = "CHECKED"
         Target.Interior.ColorIndex = 4
         Target.EntireRow.Hidden = True
     Case Else
         Target = "NOT CHECKED"
         Target.Interior.ColorIndex = 3
     End Select
 End If

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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