Highlite row as opposed to currently working cell selection

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,

I am using the code below where when a cell is selected then that cells interior color changes from yellow to blue.
When i then slected another cell this previously selected cell then reverts back to yellow.

You will see that column D and H have there own specific color & do not change to blue.

Please can you advise how to edit the code so when the is cell is selected it now turns that row blue as opposed to just that cell.
Still column D and H would have there own specific color


VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If Intersect(Target, Range("A8:I" & LastRow)) Is Nothing Then Exit Sub
    If Target.Column <> 4 And Target.Column <> 7 Then
        Range("A8:C" & LastRow).Interior.ColorIndex = 6
        Range("E8:F" & LastRow).Interior.ColorIndex = 6
        Range("H8:I" & LastRow).Interior.ColorIndex = 6
        Target.Interior.ColorIndex = 8
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Can you confirm:
Is whole row to be blue or just the row of your data ie columns A:I less D & H?
 
Upvote 0
Hi,
The column as before D and G are not to be affected by this new request.
These 2 columns should still use the old colour interior code.

So the anser to your question is A to I BUT NOT D & G

Many thanks
 
Upvote 0
Try this
Amend D2 to any cell that contains the same interior colour as colums B,D & G

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Application.ScreenUpdating = False
    Dim LastRow As Long, a As Variant
    Dim default As Long: default = Range("D2").Interior.ColorIndex
   
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If Intersect(Target, Range("A8:I" & LastRow)) Is Nothing Then Exit Sub
    If Target.Column <> 4 And Target.Column <> 7 Then
        For Each a In Array("A8:C", "E8:F", "H8:I")
            Range(a & LastRow).Interior.ColorIndex = 6
        Next
        For Each a In Array("B8:D", "G8:G")
            Range(a & LastRow).Interior.ColorIndex = default
        Next
        Cells(Target.Row, 1).Resize(, 9).Interior.ColorIndex = 8
    End If
End Sub
 
Upvote 0
Hi,
That changes the row in questiuon fine BUT it also colours the whole column B C D G green from the row row to the last row.
I need the columns left alone.

In the row in question i only need cell in column A B C E F H I changed to blue
 
Upvote 0
Try this tweak on Yongle's code...
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Application.ScreenUpdating = False
    Dim LastRow As Long, a As Variant
    Dim default As Long: default = Range("D8").Interior.ColorIndex
    
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If Intersect(Target, Range("A8:I" & LastRow)) Is Nothing Then Exit Sub
    If Target.Column <> 4 And Target.Column <> 7 Then
        For Each a In Array("A8:C", "E8:F", "H8:I")
            Range(a & LastRow).Interior.ColorIndex = 6
        Next
        Cells(Target.Row, 1).Resize(, 9).Interior.ColorIndex = 8
        For Each a In Array("D8:D", "G8:G")
            Range(a & LastRow).Interior.ColorIndex = default
        Next
        
    End If
 
Upvote 0
Yes & No

It colors the row in question fine.

But the cell at column D and G have there own specific color.
This is totaly removed & actually all of these two columns has the collor removed.
 
Upvote 0
It colors the row in question fine.
But the cell at column D and G have there own specific color.
This is totaly removed & actually all of these two columns has the collor removed.

amend the colours for D & G to match your own requirements
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Application.ScreenUpdating = False
    Dim LastRow As Long, a As Variant
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If Intersect(Target, Range("A8:I" & LastRow)) Is Nothing Then Exit Sub
    If Target.Column <> 4 And Target.Column <> 7 Then
        For Each a In Array("A8:C", "E8:F", "H8:I")
            Range(a & LastRow).Interior.ColorIndex = 6
        Next   
        Range("D8:D" & LastRow).Interior.Color = RGB(0, 255, 0)
        Range("G8:G" & LastRow).Interior.Color = RGB(100, 255, 0)
        Cells(Target.Row, 1).Resize(, 9).Interior.ColorIndex = 8
    End If
End Sub
 
Upvote 0
Let me show you why i cant do that,see attached photo.
Unless im missing something ?
 

Attachments

  • 6209.jpg
    6209.jpg
    222.7 KB · Views: 3
Upvote 0
Try this...
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Application.ScreenUpdating = False
    Dim LastRow, r As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    r = Target.Row
    If Intersect(Target, Range("A8:I" & LastRow)) Is Nothing Then Exit Sub
    If Target.Column <> 4 And Target.Column <> 7 Then
        Range("A8:C" & LastRow).Interior.ColorIndex = 6
        Range("E8:F" & LastRow).Interior.ColorIndex = 6
        Range("H8:I" & LastRow).Interior.ColorIndex = 6
        Range("A" & r & ":C" & r).Interior.ColorIndex = 8
        Range("E" & r & ":F" & r).Interior.ColorIndex = 8
        Range("H" & r & ":I" & r).Interior.ColorIndex = 8
        End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,411
Members
449,081
Latest member
JAMES KECULAH

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