Changing Row Colour When Cell Selected

hamistasty

Board Regular
Joined
May 17, 2011
Messages
208
I want the row in column A that is selected to high a light blue colour (But not the cell in A (ie. A & i)). Then when I click off the row I want it to go back to its original colour (white).

help, please?


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
Dim Changed As Range
Dim WS As Worksheet, I As Long
Set Changed = Intersect(Target, Range("A7:A" & Range("A" & Rows.Count).End(xlUp).Row))
    
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    
    If Target.Cells.Count > 1 Then Exit Sub
    
    If Not Changed Is Nothing Then
    
        Select Case Right(Target, 3)

           Case 1

           Case 2

           Case 3
           
       End Select
       
        Else
        Columns("A:CK").EntireColumn.Hidden = False
        
    End If
     Application.DisplayAlerts = True
        Application.ScreenUpdating = True
        
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Am I close?
Code:
  For I = 7 To Range("A" & Rows.Count).End(xlUp).Row
        
  If Not Intersect(Target, Range("A" & I)) Is Nothing Then
        Range("A" & Target.Row).Interior.ColorIndex = xlNone 'Remove prev coloring
        Range("A" & Target.Row).Interior.ColorIndex = 6
    Else
         Range("A" & Target.Row).Interior.ColorIndex = 6
    End If
    
    Next
 
Last edited:
Upvote 0
Ok, I've worked a bit on it and I've got this:

Code:
     For I = 7 To Range("A" & Rows.Count).End(xlUp).Row
 
  If Not Intersect(Target, Range("A" & I)) Is Nothing Then
        Range("A" & Target.Row).Interior.ColorIndex = xlNone
    Else
        Range("B" & Target.Row).EntireRow.Interior.ColorIndex = 6
    End If
 
    Next

What I'd like is:
1. It only highlights when I click a column A cell. Currently it works when I click on any cell in the row.
2. It highlights the entire row except column A (So B onwards). It currently highlights the entire row.
3. When I click off a column A cell, the highlight dissapears. It currently stays highlighted when I click off the cell.

Any help?
 
Upvote 0
Well I got it working.
Code:
If Not Intersect(target, Range("A:A")) Is Nothing Then
     Range("B" & target.Row, Range("CK" & target.Row)).Interior.ColorIndex = 6
    Else
    End If

But how do I highlight the same row white once I click OFF the cell/select a different cell?
 
Upvote 0
Try

Code:
If Not Intersect(target, Range("A:A")) Is Nothing Then
    Cells.Interior.ColorIndex = xlNone
     Range("B" & target.Row, Range("CK" & target.Row)).Interior.ColorIndex = 6
    Else
    End If

but I think the conditional formatting method is better.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

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