• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Using VBA to highlight entire Row of current cell.

Nisarga

New Member
Hello,

How do I highligh the entore Row of the current cell using macros?

I have used the below mentioned macros however they dont seem to working as per my need.



Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
Union(Target.EntireRow, Target.EntireColumn).Select
Intersect(Target.EntireRow, Target.EntireColumn).Activate
Application.EnableEvents = True
End Sub


If I use the above, the cell and its Row and Colunm is being highlighted in grey color.



Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
'Update 20140318 'Updated By dlsodders for
'Select Just Row
Static xRow

If xRow <> "" Then
With Rows(xRow).Interior
.ColorIndex = xlNone
End With
End If
pRow = Selection.Row

xRow = pRow

With Rows(pRow).Interior
.ColorIndex = 10
.Pattern = xlSolid
End With
End Sub

If I use this, then just that Row gets highlighted in Green, however any background colour to a Row gets removed.


Can anyone please help in writing a code that will just highlight the Row of current cell in light Grey color without removing the backgound color/fill ?


Thank you,
Nisarga.
 
Code goes in the sheet
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
Application.ScreenUpdating = False
    Cells.Interior.ColorIndex = 0
    Target.EntireRow.Interior.ColorIndex = 6
Application.ScreenUpdating = True
End Sub
 
Hello,

I have tried using the above code, the Row gets highlighted in yellow, however all other background colors gets removed. Also the entire first Row is going white color, including the font.
 
Hi

Try this

Code:
Sub SelRow()

    Dim i As Integer
   
    i = ActiveCell.Interior.ColorIndex
   
    ActiveCell.EntireRow.Interior.ColorIndex = 15
   
    ActiveCell.Interior.ColorIndex = i
   
End Sub
 
Not sure if you are clearly putting across what you want, highlighting or selecting entire row.

Highlighting will mean making a change to cell formatting like filling or changing a color and selecting means just selecting the entire row without changing any pre-existing cell formatting.

For highlighting, code is already provided by others above.

But if you only want to select (in your words "just highlight the Row of current cell in light Grey color without removing the backgound color/fill"), please try:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    With Target
        .EntireRow.Select
        .Activate
    End With
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub

thanks
 
Not sure if you are clearly putting across what you want, highlighting or selecting entire row.

Highlighting will mean making a change to cell formatting like filling or changing a color and selecting means just selecting the entire row without changing any pre-existing cell formatting.

For highlighting, code is already provided by others above.

But if you only want to select (in your words "just highlight the Row of current cell in light Grey color without removing the backgound color/fill"), please try:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    With Target
        .EntireRow.Select
        .Activate
    End With
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub

thanks
sir your code is owsm but i want to highlight active row and column but without loosing privius format plz reply
 
isha373
As written in Forum Rules: You should open a new thread.
( This thread is few years old and belongs to other member. )
Hint: reread How to get the Best Results at Chandoo.org
 
Back
Top