Surbrillance col et row

Bonjour,

J’utilise une macro trouvée sur le site Microsoft pour la surbrillance des colonnes et lignes la voici

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    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 = 43
        Range(Cells(.CurrentRegion.Row, .Column), Cells(.CurrentRegion.Rows.Count + .CurrentRegion.Row - 1, .Column)).Interior.ColorIndex = 43
    End With
    Application.ScreenUpdating = True
End Sub

Elle fonctionne très bien, quand je clique sur une nouvelle cellule, je souhaite désélectionner la sélection précèdent pour avoir toujours qu'une ligne ou colonne de sélectionnées

Merci de votre aide

Cordialement

Bonjour,

Un test sur la base d'une variable publique qui conserve la cellule colorée en mémoire :

Option Explicit
Public REF$
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If IsEmpty(Target) Or Target.Cells.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    If REF <> "" Then
        Range(REF).Interior.ColorIndex = 0
    End If
    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
    REF = Target.Address
End Sub

Cdlt,

Bonjour, Sairus et Ergotamine.

Autre possibilité : en début de macro on remet toutes les lignes en blancs avant d'utiliser la cellule active pour changer la couleur :

Dim l%, c%, Dl%, Dc%
Dl = Cells(Rows.Count, 1).End(xlUp).Row
Dc = Cells(1, Columns.Count).End(xlToLeft).Column
Cells.Interior.ColorIndex = 2

La solution a @ergotamine conserve la précédente sélection.

La solution que tu propose fonctionne très bien, es que je peux ajouter une délimitation de cellule pour l’exaction de la macro.

Merci a vous deux

bon j'ai trouvé beaucoup simple.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'  If Target.Count > 1 Then Exit Sub
'  If Not Intersect(Range("B2:N17"), Target) Is Nothing Then
    Calculate
'  End If
End Sub

puis dans la mise en forme conditionnelle

=OU((CELLULE("ligne")=LIGNE());CELLULE("colonne")=COLONNE())

Ça marche top merci a tous.

cordialement

Rechercher des sujets similaires à "surbrillance col row"