Highlight active cell without removing color fills from other cells?

otisvillain

Board Regular
Joined
Mar 23, 2015
Messages
77
Hey all,

This is a code I have for highlighting the active cell, so that it sticks out when keying through a worksheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Cells.Interior.ColorIndex = xlNone
Target.Interior.ColorIndex = 28


End Sub

The problem is this: It removes all fill from the worksheet, and I need to keep certain columns highlighted. I'd like to have the columns keep their fill, while only the active cell highlights. Cannot find a way around this. Any ideas?

Thanks for the help
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Did you try commenting out the first line, like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Cells.Interior.ColorIndex = xlNone
Target.Interior.ColorIndex = 28
End Sub
 
Upvote 0
The problem is this: It removes all fill from the worksheet, and I need to keep certain columns highlighted. I'd like to have the columns keep their fill, while only the active cell highlights. Cannot find a way around this. Any ideas?
How many rows of data do you have?

How many columns of data do you have?
 
Upvote 0
11 columns, 520 rows
Good, that is not a lot of data (the following is somewhat slow if there is a lot of data). This SelectionChange event code will color the row(s) and column(s) radiating out from the selected cell(s) yellow (actually, one less than the actual color of yellow in order to be able to preserve actual yellow colored cells) without changing the color of cells containing an existing color. See if it does what you want...
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Application.ScreenUpdating = False
  Application.FindFormat.Clear
  Application.ReplaceFormat.Clear
  Application.FindFormat.Interior.Color = 65534 'one less than vbYellow's value
  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 = 65534 'one less than vbYellow's value
  Target.EntireRow.Replace "", "", SearchFormat:=True, ReplaceFormat:=True
  Target.EntireColumn.Replace "", "", SearchFormat:=True, ReplaceFormat:=True
  Application.FindFormat.Clear
  Application.ReplaceFormat.Clear
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Good, that is not a lot of data (the following is somewhat slow if there is a lot of data). This SelectionChange event code will color the row(s) and column(s) radiating out from the selected cell(s) yellow (actually, one less than the actual color of yellow in order to be able to preserve actual yellow colored cells) without changing the color of cells containing an existing color. See if it does what you want...
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Application.ScreenUpdating = False
  Application.FindFormat.Clear
  Application.ReplaceFormat.Clear
  Application.FindFormat.Interior.Color = 65534 'one less than vbYellow's value
  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 = 65534 'one less than vbYellow's value
  Target.EntireRow.Replace "", "", SearchFormat:=True, ReplaceFormat:=True
  Target.EntireColumn.Replace "", "", SearchFormat:=True, ReplaceFormat:=True
  Application.FindFormat.Clear
  Application.ReplaceFormat.Clear
  Application.ScreenUpdating = True
End Sub

Excellent, thank you for the reply! I'll try this code out and see how it works. I appreciate your help
 
Upvote 0
What happens when I do that is the active cell stays filled with the color, even when I move into another cell
 
Upvote 0
Have you checked the link I provided in post #4?
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,218
Members
453,024
Latest member
Wingit77

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