Highlight active row Except cells that are currently highlighted

Falko26

Board Regular
Joined
Oct 13, 2021
Messages
99
Office Version
  1. 365
Platform
  1. Windows
Hey Team,
I have this code that highlights the entire row of the active cell. But I don't want it to mess with the cells I already have highlighted in that row.

Is there a way to modify this to only highlight cells that are not currently highlighted?? This way my highlighted cells are not affected?

Thanks,

VBA Code:
Dim i As Long

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If i > 3 Then
    
Rows(i).EntireRow.Interior.ColorIndex = 0
End If
i = Target.Row
If i > 3 Then
Rows(i).EntireRow.Interior.Color = RGB(255, 242, 204)
End If
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try a conditional format.

Step a) Change your code to this:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Target.Row > 3 Then
    Application.ScreenUpdating = True
  End If
End Sub


Step b). Put the following conditional formatting on your sheet:
1. Select all cells .
2. Create a conditional formatting rule, and select the Formula option 3.
3. Enter a formula:
VBA Code:
=ROW()=CELL("row")
4. Select Format to put the fill color in the cells
 
Upvote 0
Solution
Try a conditional format.

Step a) Change your code to this:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Target.Row > 3 Then
    Application.ScreenUpdating = True
  End If
End Sub


Step b). Put the following conditional formatting on your sheet:
1. Select all cells .
2. Create a conditional formatting rule, and select the Formula option 3.
3. Enter a formula:
VBA Code:
=ROW()=CELL("row")
4. Select Format to put the fill color in the cells
Thanks this works! I was doing something similar to this before but it was really bogging down the spreadsheet. That's why I turned to VBA in the first place. But after recreating the Conditional formatting rule it seems to work a lot faster now!

Thanks!
 
Upvote 0
Hello!

I've got the same problem. I tried your code and works the same with my code. In my case I need to highlight only the rows in my table and I have 3 different tables in the same sheet. when I clicked the cell it also highlight the same row in 3 tables. can you help me to formulate my sheet that only highlight the specific row in the specific table.

Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

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