• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Selection Change Event

Shay A

Member
Hi,
I found this code to highlight current row and column within the current region/
Is it possible to mend it so it doesn't override previous formatting?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  ' Clear the color of all the cells
  Cells.Interior.ColorIndex = 0
  If IsEmpty(Target) Or Target.Cells.Count > 1 Then Exit Sub
  Application.ScreenUpdating = False
  With ActiveCell
  ' Highlight the row and column that contain the active cell, within the current region
  Range(Cells(.Row, .CurrentRegion.Column), Cells(.Row, .CurrentRegion.Columns.Count + .CurrentRegion.Column - 1)).Interior.ColorIndex = 8
  Range(Cells(.CurrentRegion.Row, .Column), Cells(.CurrentRegion.Rows.Count + .CurrentRegion.Row - 1, .Column)).Interior.ColorIndex = 8
  End With
  Application.ScreenUpdating = True
End Sub


and this is the link:

https://msdn.microsoft.com/VBA/Excel-VBA/articles/highlight-the-active-cell-row-or-column


TY
 
Last edited by a moderator:

Better than this bad link is to warm a pair of neurons
in order to not alter any formatting, just selecting
expected column and row … Totally useless but
nothing to amend, just think and create a good code ! (4 codelines …)
 
In the SelectionChange event procedure,
desactivate first events (see in VBA inner help EnableEvents property),
Select the Column or the Row (or both via Union) of the Target
then Activate the Target and finally reactivate events …

Easy but as yet written totally useless and may be a mess for users !
 

As written, first read VBA inner help for each statement given
in my previous post then follow directions when writing your code …
 
Back
Top