Conditional Formatting Based on Active Cell

cheesiepoof05

Board Regular
Joined
Dec 30, 2010
Messages
82
Hello all,

I have some code that I use to highlight the first column and row of the active cell I'm in to make it easier to see. Then when I click out of that cell it removes the highlighted that it had added and highlights the new location. The code is baked into the tab itself by right clicking on sheet name and selecting view code. My problem is that some of my workbooks have conditional formatting that overrides my highlighting macro. Is there a way around this conundrum? Thank you

Current code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Rows("1:1").Interior.ColorIndex = xlNone
Columns(1).Interior.ColorIndex = xlNone
Cells(ActiveCell.Row, 1).Interior.ColorIndex = 33
Cells(1, ActiveCell.Column).Interior.ColorIndex = 33
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Conditional Formatting trumps all other formatting, whether set manually or with the VBA code you posted.
So essentially, you would need to "turn it off", at least for the active cells/rows.
That could be a very tricky process, because you do not want to permanently remove the Conditional Formatting, just temporarily.
Because you are dealing with a multi-cell range that could conceivably have multiple Conditional Formatting rules, this could get rather complicated.
You may want to look to see if you can incorporate the method that Chip Pearson mentioned here: https://answers.microsoft.com/en-us...rmatting/43fafd7e-5464-e011-8dfc-68b599b31bf5

The only other option I can think off is to replace your Conditional Formatting, and replace it with VBA code in your Event Procedure code above.
That could get quite resource intensive, as it may have to re-evaluate every single cell every time you select a new cell in your worksheet (unless you can figure out a way to do it incorporating the Worksheet_Change event procedure as well).

Quite frankly, if it was me, and this is just a convenience thing, I would probably say it is not worth the effort and just leave it "as-is", knowing that anyone cells that have Conditional Formatting applied will be overridden by those rules.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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