MFC en vba pour bordures

  • Initiateur de la discussion Initiateur de la discussion fr832
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

fr832

XLDnaute Occasionnel
Bonsoir je cherche par le biais de ce code de mettre en forme à la fin de la saisie le contour de mon tableau et l'interieur.

Mais ce code bug , serait il possible de m'aider , par avance merci, amitiés


Code:
Public DerLig As Long
Sub mfc()
With Range(Cells(DerLig, 1), Cells(DerLig, 10))
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideVertical)
        [COLOR="Red"].LineStyle = xlContinuous[/COLOR]       
       .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    End With
End Sub
 
Re : MFC en vba pour bordures

Bonsoir,
Je ne vois aucune sélection préalable dans ce code ?! donc la selection s'applique à une seule cellule, et de fait pour les traits intérieurs forcément...
Tu utilises l'instruction with
Code:
Public DerLig As Long
Sub mfc()
DerLig = 5
With Range(Cells(DerLig, 1), Cells(DerLig, 10))
    .Borders(xlEdgeBottom).LineStyle = xlNone
    With .Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With .Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With .Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With .Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End With

End Sub
A+
kjin
 
Re : MFC en vba pour bordures

Bonsoir le fil, kjin, fr832

On doit pouvoir simplifier ainsi
Code:
Sub mfc2()
    DerLig = 5
 
    With Range(Cells(DerLig, 1), Cells(DerLig, 10))
 
        With .Borders
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
 
        .Borders(xlEdgeBottom).LineStyle = xlNone
        .Borders(xlInsideVertical).Weight = xlThin
 
    End With
End Sub
A plus
 
Re : MFC en vba pour bordures

Bonjour,soenda , Kjin merci pour votre aide ça me met bien une ligne avec contour et interieur mais au fur et à mesure que je remplie mon tableau ça descend et ne garde pas les contours et iterlignes sur les lignes précédentes.

J'avais essayer par l'enregistreur de macros mais n'y suis pas arruivé d'ou ma demande d'aide sur le forum.

Ce que je cherche à faire c'est que au fur et a mesure que mon tableau se remplie via un userform, ça me mette les contour et interrieur.

Si l'intérieur et contour sont en trait fin ce n'est pas un problème, je dis ça au cas ou ça simplifierai le code.

Par avance merci à vous et bon week end, amitiés
 
Re : MFC en vba pour bordures

Re bonjour à tous voila j'ai ce code qui fonctionne impec sauf qu'il a la formule mod(ligne() d'intégré et je n'arrive pas a supprimer ce mod ligne sans que ça bugg.

Par avance merci

Code:
Public DerLig As Long
Sub mfc()
With Range(Cells(DerLig, 1), Cells(DerLig, 10))
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=ET(" & Cells(DerLig, 1).Address & "<>"""";MOD(LIGNE();2))"
    With .FormatConditions(1).Borders
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    .FormatConditions(1).Interior.ColorIndex = 35
    .FormatConditions.Add Type:=xlExpression, Formula1:="=" & Cells(DerLig, 1).Address & "<>"""""
    With .FormatConditions(2).Borders
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End With
End Sub

😕
 
Re : MFC en vba pour bordures

C'est bon j'ai trouvé en faisant ce code
Code:
Public DerLig As Long
Sub mfc()
With Range(Cells(DerLig, 1), Cells(DerLig, 10))
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlExpression, Formula1:=" & Cells(DerLig, 1).Address & " <> """"""
    With .FormatConditions(1).Borders
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    .FormatConditions.Add Type:=xlExpression, Formula1:="=" & Cells(DerLig, 1).Address & "<>"""""
    With .FormatConditions(2).Borders
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End With
End Sub

bonne journée à tous
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
14
Affichages
484
T
  • Question Question
XL pour MAC Recherche date
Réponses
5
Affichages
2 K
tdenis
T
M
Réponses
8
Affichages
2 K
Michelrib
M
Réponses
8
Affichages
1 K
D
Réponses
1
Affichages
675
Compte Supprimé 979
C
C
  • Question Question
Réponses
13
Affichages
3 K
Retour