Highlighting a section of selected row

jeffmoseler

Well-known Member
Joined
Jul 16, 2004
Messages
540
I found this code online that highlights the whole row of whatever row you have selected. It works great except that you can't have any other cell in the entire sheet filled with any color or it disappears when you select another cell. I would like to have this code select the active row, columns A through M only. And when it refreshes to delete all fill colors from A2 to M34. Let me know how I could tweak this to get it to work.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    ' Clear the color of all the cells
    Cells.Interior.ColorIndex = 0
    With Target
        ' Highlight the entire row and column that contain the active cell
        .EntireRow.Interior.ColorIndex = 8
    End With
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try This:
Code:
[COLOR=#0000ff]Private Sub[/COLOR] Worksheet_SelectionChange([COLOR=#0000ff]ByVal[/COLOR] Target [COLOR=#0000ff]As[/COLOR] Range)
    [COLOR=#0000ff]If [/COLOR]Target.Cells.Count > 1 [COLOR=#0000ff]Then Exit Sub[/COLOR]
    Application.ScreenUpdating = F[COLOR=#0000ff]alse[/COLOR]
[COLOR=#008000]    ' Clear the color of all the cells
[/COLOR]    Range("A2:M34").Interior.ColorIndex = 0
  [COLOR=#0000ff]  With[/COLOR] Target
      [COLOR=#008000]  ' Highlight the entire row and column that contain the active cell[/COLOR]
        CurrentRow = ActiveCell.Row
        [COLOR=#0000ff]If [/COLOR]CurrentRow >= 2 [COLOR=#0000ff]And [/COLOR]CurrentRow <= 34 [COLOR=#0000ff]Then[/COLOR]
        Range(Cells(CurrentRow, 1), Cells(CurrentRow, 13)).Interior.ColorIndex = 8
        [COLOR=#0000ff]Else
            Exit Sub
        End If
    End With[/COLOR]
    Application.ScreenUpdating = [COLOR=#0000ff]True[/COLOR]
[COLOR=#0000ff]End Sub[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,632
Messages
6,056,439
Members
444,864
Latest member
Thundama

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