Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

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 !

tactic6

XLDnaute Impliqué
Bonjour le forum
à l'aide de l'enregistreur de macro j'ai crée un code pour "fabriquer" à la demande les bordures d'une feuille

J'ai supprimé tout ce qui était inutile et je me demande (je sais bien qu'en période de fêtes c'est un peu dur) si il n'y a pas moyen de lui faire faire un petit régime amincissant
Voici le code ci dessous et merci pour votre aide

Code:
Sub Bordure2()
'
' Bordure2 Macro
'

'
  

    Range("B14:K14").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
     Range("C14:G14").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    Range("I14").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
      End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
     End With
     Range("J14").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
     End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
    End With
    Range("B15:K52").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
    End With
    Range("C15:G52").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
    End With
    Range("I15:I52").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
    End With
    Range("K15:K52").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
    End With
     Range("B54:K59").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
    End With
    Range("C54:C59").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
    End With
    Range("D54:D59").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
    End With
    Range("J54:J59").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
     End With
    Range("B54:D54").Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
     End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
    End With
       Range("B54").Select
    Selection.Font.Size = 11
    With Selection.Font
        .ColorIndex = xlAutomatic
    End With
    Range("B54").Select
    With Selection.Font
        .Name = "Arial"
        .FontStyle = "Normal"
        .Size = 10
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
        .ThemeFont = xlThemeFontNone
    End With
End Sub

Bon dimanche à tous
 
Re : Reduire code

Bonjour à tous,

Tu peux "amincir" ton code pour tes plages ...
Code:
Sub Test()
Dim mesplages As Range
Set mesplages = Range( _
"B14:K14,C14:G14,I14,J14,B15:K52,C15:G52,I15:I52,K15:K52,B54:K59,C54:C59,D54:D59,J54:J59,B54:D54")
    With mesplages
        .Borders(xlEdgeLeft).LineStyle = xlContinuous
        .Borders(xlEdgeTop).LineStyle = xlContinuous
        .Borders(xlEdgeBottom).LineStyle = xlContinuous
        .Borders(xlEdgeRight).LineStyle = xlContinuous
    End With
    With Range("B54").Font
        .Name = "Arial"
        .FontStyle = "Normal"
        .Size = 10
    End With
End Sub

A +
🙂
 
Re : Reduire code

Bonjour

ma p'tite solution comme ça

VB:
Sub Bordure2()
  Range("B14:K14, C14:G14, I14, J14, B15:K52, C15:G52, I15:I52, K15:K52, B54:K59, C54:C59, D54:D59, J54:J59, B54:D54") _
    .BorderAround LineStyle:=xlContinuous, ColorIndex:=xlAutomatic
  With Range("B54").Font
    .Size = 10
    .ColorIndex = xlAutomatic
    .Name = "Arial"
    .FontStyle = "Normal"
    .Underline = xlUnderlineStyleNone
    .ThemeFont = xlThemeFontNone
  End With
End Sub
 
Re : Reduire code

Re


Comme Banzai64 mais en partant du code de James007
(pour trois gramme de moins 😉 )

Code:
Sub Test()
Dim mesplages As Range
Set mesplages = Range( _
"B14:K14,C14:G14,I14,J14,B15:K52,C15:G52,I15:I52,K15:K52,B54:K59,C54:C59,D54:D59,J54:J59,B54:D54")
mesplages.BorderAround , LineStyle:=xlContinuous
Range("B54").Font.FontStyle = "Normal"
End Sub
PS: tactic6
Le code ci-dessus, celui de James007 et celui de Banzai64 font ce que fait ton Bordure2
Tu demandes une réduction de code puis quand tu as divers exemples de codes réduits
tu hésites à les utiliser ????
(Je viens de tester Bordure2 initiale puis les autres codes VBA)
 
Dernière édition:
Re : Reduire code

Re tout le monde
Staple 1600 c'est presque pareil mon bordure à le contour en plein et l'intérieur de la zone B15 K52 en pointillé
rien de bien méchant et en plus tellement plus simple que le temps de l'ecrire j'adopte
 
- 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
M
Réponses
8
Affichages
2 K
Michelrib
M
T
  • Question Question
XL pour MAC Recherche date
Réponses
5
Affichages
2 K
tdenis
T
Réponses
8
Affichages
1 K
S
Réponses
4
Affichages
2 K
stage_ferrit
S
L
Réponses
9
Affichages
1 K
H
Réponses
2
Affichages
1 K
H
C
  • Question Question
Réponses
13
Affichages
3 K
C
Réponses
2
Affichages
1 K
candice**
C
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…