yurip

New Member
Joined
Jun 26, 2015
Messages
10
Hello All, I use the below code to change the color of a row of cells when a user double clicks. Problem is the row beyond the table its meant to act on is affected. Is there a way to restrict EntireRow so that it only acts within a range? Thanks!

Code:
Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
     
    If Target.Interior.Color = vbGreen Then
    Cancel = True
    Target.EntireRow.Interior.ColorIndex = 22
    Target.Interior.Color = vbRed
    ElseIf Target.Interior.Color = vbRed Then
    Cancel = True
    Target.EntireRow.Interior.ColorIndex = 0
    Target.Interior.Color = vbYellow
    
        
    ElseIf Target.Interior.Color = vbYellow Then
    Cancel = True
    Target.EntireRow.Interior.ColorIndex = 35
    Target.Interior.Color = vbGreen
    End If
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Which range would you want to restrict it too?
 
Upvote 0
I was trying to have the code only work within the A3:I2455 range but every time I tried to apply that, I would make a mistake or make my code run an infinite loop.
 
Upvote 0

Forum statistics

Threads
1,215,506
Messages
6,125,193
Members
449,213
Latest member
Kirbito

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