highlighting active row problem

njbeancounter

Board Regular
Joined
Oct 7, 2002
Messages
158
The following code removes all interior colors and then highlights the row of the active cell in yellow:


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Cells.Interior.Color = xlNone
ActiveCell.Cells.EntireRow.Interior.Color = vbYellow
End Sub


How can I modify this to allow some rows to be highlighted a different color?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You want some fixed rows (which ones) to be highlighted color X (what is X) and the activecell's row to be yellow?
 
Upvote 0
I want to be able to keep some rows highlighted red, for instance. Not necessarily the same fixed row, just any row could be highlighted not yellow, and remain highlighted, but the yellow would still be highlighted as the active row.
 
Upvote 0
I want to be able to keep some rows highlighted red, for instance. Not necessarily the same fixed row, just any row could be highlighted not yellow, and remain highlighted, but the yellow would still be highlighted as the active row.
Don't see how you would do that with a selection_change event unless the red rows are fixed. Otherwise, when you select a new cell, how would the rows you want to be red get communicated?
 
Upvote 0
If you do not mind highlighting only cells that have no color and leaving colored cells untouched even if in the highlighted row(s), then you can use this event code...
Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
  Application.FindFormat.Clear
  Application.ReplaceFormat.Clear
  Application.FindFormat.Interior.Color = vbYellow
  Application.ReplaceFormat.Interior.Color = xlNone
  Cells.Replace "", "", SearchFormat:=True, ReplaceFormat:=True
  Application.FindFormat.Clear
  Application.ReplaceFormat.Clear
  Application.FindFormat.Interior.Color = xlNone
  Application.ReplaceFormat.Interior.Color = vbYellow
  Target.EntireRow.Replace "", "", SearchFormat:=True, ReplaceFormat:=True
  Application.FindFormat.Clear
  Application.ReplaceFormat.Clear
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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