OVH Cloud OVH Cloud

[VBA] réduction de la taille d'une macro

6 réponses
Avatar
Michel.P
Bonjour à toutes et à tous
J'ai lancé la création d'une macro pour récupérer
le code, mais je trouve qu'il est un peu long...
y a t-il un moyen pour raccoursisr ce code ?
(quand clik sur bouton, de B11:B15 cases sont
barrées en diagonales)

merci du tuyau

Sub Macro5()
Range("B11:C15").Select
With Selection.Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With

Selection.Borders(xlInsideHorizontal).LineStyle =
xlNone
End Sub

--
Amicalement
Michel . P

6 réponses

Avatar
FxM
Bonjour Michel,

Pas fondamentalement différent ..
Je ne sais pourquoi Excel ne prend pas en compte les diagonales lorsque
tu lui dis borders. Ca nous mène à un truc que j'aurais espéré encore un
peu plus compact mais bon :o)

Sub Macro5()
Range("B11:C15").Select
With Selection
With .Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
End Sub

@+
FxM


Michel.P wrote:

Bonjour à toutes et à tous
J'ai lancé la création d'une macro pour récupérer le code, mais je
trouve qu'il est un peu long...
y a t-il un moyen pour raccoursisr ce code ? (quand clik sur bouton, de
B11:B15 cases sont barrées en diagonales)

merci du tuyau

Sub Macro5()
Range("B11:C15").Select
With Selection.Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub



Avatar
michdenis
Bonjour Michel,

'---------------------------
Sub Macro5()
With Range("B11:C15")
.BorderAround xlContinuous, xlMedium, xlColorIndexAutomatic
With .Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End With

End Sub
'---------------------------


Salutations!



"Michel.P" a écrit dans le message de
news:
Bonjour à toutes et à tous
J'ai lancé la création d'une macro pour récupérer
le code, mais je trouve qu'il est un peu long...
y a t-il un moyen pour raccoursisr ce code ?
(quand clik sur bouton, de B11:B15 cases sont
barrées en diagonales)

merci du tuyau

Sub Macro5()
Range("B11:C15").Select
With Selection.Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With

Selection.Borders(xlInsideHorizontal).LineStyle xlNone
End Sub

--
Amicalement
Michel . P
Avatar
michdenis
Bonjour Michel,

Il y a aussi ceci :

'------------------
Sub Macro5()
Dim A As Integer
With Range("B11:C15")
.BorderAround xlContinuous, xlMedium, xlColorIndexAutomatic
For A = 5 To 6
With .Borders(A)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Next
End With
End Sub
'------------------


Salutations!



"Michel.P" a écrit dans le message de
news:
Bonjour à toutes et à tous
J'ai lancé la création d'une macro pour récupérer
le code, mais je trouve qu'il est un peu long...
y a t-il un moyen pour raccoursisr ce code ?
(quand clik sur bouton, de B11:B15 cases sont
barrées en diagonales)

merci du tuyau

Sub Macro5()
Range("B11:C15").Select
With Selection.Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With

Selection.Borders(xlInsideHorizontal).LineStyle xlNone
End Sub

--
Amicalement
Michel . P
Avatar
¤ve
Salut Michel,
Voilà :
Sub Macro5()
Dim I As Integer
For I = 5 To 10
With [B11:C15].Borders(I)
.LineStyle = 1
.Weight = -4138
End With
Next I
End Sub

Hervé.

"Michel.P" a écrit dans le message de
news:
Bonjour à toutes et à tous
J'ai lancé la création d'une macro pour récupérer
le code, mais je trouve qu'il est un peu long...
y a t-il un moyen pour raccoursisr ce code ?
(quand clik sur bouton, de B11:B15 cases sont
barrées en diagonales)

merci du tuyau

Sub Macro5()
Range("B11:C15").Select
With Selection.Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With

Selection.Borders(xlInsideHorizontal).LineStyle > xlNone
End Sub

--
Amicalement
Michel . P



Avatar
Michel.P
Merci à vous deux, je prends le tout et v'ai
exploiter tout ça..
bon week end

--
Amicalement
Michel . P
Avatar
Michel.P
Merci hervé, c'est encore lus court ;-)

¤ve a utilisé son clavier pour écrire :
Salut Michel,
Voilà :
Sub Macro5()
Dim I As Integer
For I = 5 To 10
With [B11:C15].Borders(I)
.LineStyle = 1
.Weight = -4138
End With
Next I
End Sub

Hervé.


--
Amicalement
Michel . P