Selection Change to Format Cells in tha particular Row

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi,
I like to be able to highligth the Cell in column A after I pick a cell in that same row.

I got a formated table in a worksheet.
If I either mouse over or select a cell in that row I like to change the back color of that row.. Idealy from A:J in that row so I know which row has been selected or clicked.

Maybe even the row and the Column but only within.

So I got data in A3:I20.. if I select the Cell from B3:I20 I would like to highligth the row A3:J3

Hope I have it made clear what I am after.

I found a code on the net but it is not quite what I am after.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Me.Range("A1:XFD1048576").Interior.ColorIndex = 0
    Target.EntireRow.Interior.ColorIndex = 6
End Sub

Many thanks

Albert
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
perhaps

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Row = 1 Or Target.Cells.CountLarge > 1 Then Exit Sub
    If Not Intersect(Range("B:I"), Target) Is Nothing Then
        Me.Range("A:J").Interior.ColorIndex = 0
        Cells(Target.Row - 1, 1).Resize(, 10).Interior.ColorIndex = 6
    End If
End Sub
 
Upvote 0
Hi Thanks for your reply,

unfortunately I am getting a 1004 runtim error on
Code:
Me.Range("A:J").Interior.ColorIndex = 0
 
Upvote 0
I have been looking at the web and found a code.

So when I use that code in a worksheet with no format on it it works fine but on every Sheet which has formating in it "just colors" no formular or anything.. then I get also a 1004 runtime error.
Cells.Interior.ColorIndex = xlNone

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Dim i As Integer

    Cells.Interior.ColorIndex = xlNone

    'loop to color down a column
    For i = 1 To Target.Row
        Cells(i, Target.Column).Interior.ColorIndex = 6
    Next
    'loop to color down a column
    For i = 1 To Target.Column
        Cells(Target.Row, i).Interior.ColorIndex = 6
    Next
End Sub

it is getting there but just not quite there yet.

Many thanks

Albert
 
Last edited:
Upvote 0

Forum statistics

Threads
1,207,288
Messages
6,077,546
Members
446,287
Latest member
lihong3210

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