Conditional formatting based on selected row?

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
275
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2011
Platform
  1. Windows
  2. MacOS
I am interested in having the font color in a particular cell change color if the user has selected any cell on that same row. (For example, if they select a cell anywhere on row 15, the font color in cell A15 would change to red. Otherwise, it would be black.) I was able to figure out how to do this using the Workbook_SelectionChange sub. However, I need to do it without using VBA code, because whenever the sub runs, it clears the clipboard and thus my users cannot do a Copy & Paste on the sheet. I have been trying to figure out how to make this work using Conditional Formatting, but so far haven't had any luck. I haven't been able to find any existing posts about this, so I'm not sure if it is even possible to do this using Conditional Formatting. Anyone know if it is, and if so, any idea how I would do it?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Please provide a little more information about the expected behaviour.. do you expect the colours to change back to black or their previously assigned colour when leaving the row?

or would you like them to remain red?

Try this VBA Code
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 Cells.Interior.ColorIndex = 0
 Dim MyRange As Range
 Set MyRange = Range("A:A").EntireRow
 MyRange.Font.ColorIndex = 1
 If Not Intersect(Target, MyRange) Is Nothing Then
  Cells(Target.Row, "A").Font.ColorIndex = 3
 End If
End Sub

This will return the A:A range to black - although, it will also prevent you to assign any colours in that range
 
Upvote 0
I want the color to return to black when the user leaves the row.

Thank you for the reply. However, in my post I said that I needed to do this without VBA code. When the Worksheet_SelectionChange sub runs it is clearing the clipboard, so Copy & Paste is not possible on the worksheet, and my users sometimes need to be able to do that. So using VBA code for this is not a workable solution. That is why I am hoping to do it with Conditional Formatting.
 
Upvote 0
Give this a try. It does involve vba but should still allow copy/paste.
  1. Select all of column A by clicking its heading label
  2. Use Conditional Formatting -> New rule.. -> Use a formula to determine ... -> Format values where this formula is true: =CELL("row")=ROW() -> Format... -> On the Font tab select red -> OK -> OK
  3. Put this code in the worksheet's module
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Actually, one further question:

If I select more than one row, only the top-most row in the selection changes font color. Is there a way to change the formula so the font color in ALL the rows selected will turn red?
 
Upvote 0
Assuming that column Z is available as a helper, see if this is any good.

CF Rule is
Excel Formula:
=AND(ROW()>=Z$1,ROW()<=Z$2)

with:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Range("Z1").Value = Selection.Row
  Range("Z2").Value = Selection.Row + Selection.Rows.Count - 1
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,034
Members
448,940
Latest member
mdusw

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