View Single Post
 
Old 04-28-2018, 07:00 AM
lucato lucato is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Apr 2018
Location: Brazil
Posts: 6
lucato is on a distinguished road
Default VBA highlight the entire row issue

Hi folks, I was looking for how to highlight the entire row and found in this forum the VBA code bellow. The problem with such code is that it messed (removed) the all styles in my spreadsheet. So, I've lost all columns styles I had set. I know there is the option to SHIF+SPACE to select the entire row, but does anybody know how to have a code that doesn't remove the colors from columns and so on, so do not mess the style of a spreadsheet.? Thanks.


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
    Target.Parent.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
Reply With Quote