What I want to achieve is to highlight active row or column. I used VBA solutions but everytime Selection_change
event is used I am loosing chance to undo any changes in my worksheet.
Is there a way to somehow hightlight active row / column without using VBA?
On the sheets Selection_change event call the following:
This is long format for clarity!
The best you can get is using conditional Formatting.
Create two formula based rules:
=ROW()=CELL("row")
=COLUMN()=CELL("col")
As shown in:
The only drawback is that every time you select a cell you need to recalculate your sheet. (You can press "F9")
First of all Thanks! I had just created a solution with highlighting cells, using the Selection_Change and changing a cells content. I did not know it would disable Undo. I found a way to do it by using combining conditional formatting, Cell() and the Selection_Change event. This is how I did it.
Range("A1").Calculate
. This way it is done every time the user moves around, and as the Selection_Change is NOT changing any values/formats etc in the sheet, Undo is not disabled.This works for me.
I don't think it can be done without using VBA, but it can be done without losing your undo history:
In VBA, add the following to your worksheet object:
Create a new VBA module and add the following:
Finally, use conditional formatting to highlight cells based on the 'HighlightSelection' formula:
Using conditional formatting, instead of highlighting the entire row and column, it is possible to highlight the row to the left of the cell and the column above the cell with the code below:
An alternative to
Range.Calculate
is usingActiveWindow.SmallScroll
The only downside is that the screen flickers for a split second after making a new selection. While scrolling manually, you need to make sure the new selection moves out of the screen (window) completely, for it to work. Which is why, in below code, we need to scroll enough to get all visible rows out of the screen view and then scroll back to same position -to force screen refresh for conditional formatting.Credits: Rory Archibald https://www.experts-exchange.com/questions/28275889/When-is-excel-conditional-formatting-refreshed.html