VBA: Detection bord tableau

maitrebanjo Messages postés 1 Statut Membre -  
Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour à tous,

J'ai codé le code ci dessous qui me permet de mettre en rouge les bords de la ligne de ma cellule active:


Dim oldtarget As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set champ = Range("A1:BZ" & Range("TableauDeBord").Rows.Count + 1)
If Not oldtarget Is Nothing Then oldtarget.EntireRow.Borders.LineStyle = xlNone
If Not Intersect(Target, champ) Is Nothing Then
If Target.Count = 1 Then
With Target.EntireRow
With .Borders(xlEdgeTop)
.Weight = xlMedium
.Color = RGB(255, 0, 0)
End With
With .Borders(xlEdgeBottom)
.Weight = xlMedium
.Color = RGB(255, 0, 0)
End With
End With
End If
End If
Set oldtarget = Target
End Sub


J'aimerais savoir si il y avait une possibilité pour que la mise en forme ne se fasse que jusqu'à la dernière colonne du tableau?

2 réponses

  1. michel_m Messages postés 18903 Date d'inscription   Statut Contributeur Dernière intervention   3 320
     
    Bonjour

    tu peux connaitre la ligne de Target par la fonction "row"

    l
    igne=target.row


    la zone à encadrer est
     zone=Range (cells(ligne,"A"),cells(ligne,"BZ"))


    et enfin tu remplaces
    With Target.EntireRow
    With .Borders(xlEdgeTop)...
    par
    With Zone
    With .Borders(xlEdgeTop)...

     Michel
    0
  2. Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   1 784
     
    Bonjour,

    Tu peux simplement remplacer :
    With Target.EntireRow
    Par :
    With Intersect(champ, Target.EntireRow) 


    Cordialement
    Patrice
    0