OVH Cloud OVH Cloud

MEFC simplification code

3 réponses
Avatar
j-pascal
Bonjour à tous,
Cette portion de code me paraît très lourde, pourriez-vous me dire comment
la simplifier ? D'avance, merci !

For Each c In Worksheets(1).Range("L8:L202")

If c.Value = 1 Then

With c.Offset(0, -1).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32


With c.Offset(0, -2).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -3).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -4).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -5).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -6).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -7).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -9).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

End With
End With
End With
End With
End With
End With
End With
End With
End With
End With





Else

With c.Offset(0, -1).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -2).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -3).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -4).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -5).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -6).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -7).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -9).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

End With
End With
End With
End With
End With
End With
End With
End With
End With



End If

Next

End Sub

3 réponses

Avatar
MichDenis
Bonsoir j-pascal,

Essaie ceci :

'------------------------------------------------
Sub Formatage()

Dim Rg As Range, Rg1 As Range, C As Range
Set Rg = Worksheets(1).Range("L8:L202")

Application.ScreenUpdating = False
For Each c In Rg
If c.Value = 1 Then
Set Rg1 = c.Offset(, -9).Resize(, 10)
With Rg1.Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32
End With
Else
Set Rg1 = c.Offset(, -9).Resize(, 10)
aa = Rg1.Address
With Rg1.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16
End With
End If
Next
Set Rg1 = Nothing: Set Rg = Nothing: Set C = Nothing

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


Salutations!




"j-pascal" a écrit dans le message de news: %
Bonjour à tous,
Cette portion de code me paraît très lourde, pourriez-vous me dire comment
la simplifier ? D'avance, merci !

For Each c In Worksheets(1).Range("L8:L202")

If c.Value = 1 Then

With c.Offset(0, -1).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32


With c.Offset(0, -2).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -3).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -4).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -5).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -6).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -7).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -9).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

End With
End With
End With
End With
End With
End With
End With
End With
End With
End With





Else

With c.Offset(0, -1).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -2).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -3).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -4).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -5).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -6).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -7).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -9).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

End With
End With
End With
End With
End With
End With
End With
End With
End With



End If

Next

End Sub
Avatar
MichDenis
Bonsoir j-pascal,

Essaie ceci :

'---------------------------------------
Sub Formatage()

Dim Rg As Range, Rg1 As Range
Set Rg = Worksheets(1).Range("L8:L202")

Application.ScreenUpdating = False
For Each c In Rg
If c.Value = 1 Then
Set Rg1 = c.Offset(, -9).Resize(, 10)
With Rg1.Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32
End With
Else
Set Rg1 = c.Offset(, -9).Resize(, 10)
With Rg1.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16
End With
End If
Next
End Sub
'---------------------------------------


Salutations!


"j-pascal" a écrit dans le message de news: %
Bonjour à tous,
Cette portion de code me paraît très lourde, pourriez-vous me dire comment
la simplifier ? D'avance, merci !

For Each c In Worksheets(1).Range("L8:L202")

If c.Value = 1 Then

With c.Offset(0, -1).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32


With c.Offset(0, -2).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -3).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -4).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -5).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -6).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -7).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -9).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

End With
End With
End With
End With
End With
End With
End With
End With
End With
End With





Else

With c.Offset(0, -1).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -2).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -3).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -4).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -5).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -6).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -7).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -9).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

End With
End With
End With
End With
End With
End With
End With
End With
End With



End If

Next

End Sub
Avatar
GVentre
Bonjour J-pascal,

plus léger en appliquant le style non pas cellule par cellule mais sur
la plage de cellule:

Sub test()
For Each c In Worksheets(1).Range("L8:L222")
If c.Value = 1 Then
With Range(c.Offset(0, -1), c.Offset(0, -9)).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

End With
Else
With Range(c.Offset(0, -1), c.Offset(0, -9)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

End With
End If
Next
End Sub

Cordialement,
GVentre



Bonjour à tous,
Cette portion de code me paraît très lourde, pourriez-vous me dire comment
la simplifier ? D'avance, merci !

For Each c In Worksheets(1).Range("L8:L202")

If c.Value = 1 Then

With c.Offset(0, -1).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32


With c.Offset(0, -2).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -3).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -4).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -5).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -6).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -7).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

With c.Offset(0, -9).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlMedium
.ColorIndex = 32

End With
End With
End With
End With
End With
End With
End With
End With
End With
End With





Else

With c.Offset(0, -1).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -2).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -3).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -4).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -5).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -6).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -7).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -8).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

With c.Offset(0, -9).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 16

End With
End With
End With
End With
End With
End With
End With
End With
End With



End If

Next

End Sub