Sub essai()
Dim i As Integer
Dim j As Integer
Sheets(1).Activate
For i = 15 To 25 Step 2
For j = 2 To 10 Step 2
Cells(i, j).Interior.ColorIndex = 3
Cells(i + 1, j - 1).Interior.ColorIndex = 43
Next j
Next i
End Sub
[h=3]Damier[/h]Sélectionner le tableau et appliquer une MEFC noire avec comme condition la formule :
=MOD(LIGNE()+COLONNE();2)
Alors voici traduit en VBA (avec une petite touche personnelle quant à certains choix ), la citation de mon premier message dans ce fil (voir plus bas: message de 5h56)Bonjour à tous.
Si il y a d'autres exemples je suis preneur.
Sub mDamier()
Dim Damier As Range: Set Damier = Range("A1:J10")
With Damier
.ColumnWidth = 7.14: .RowHeight = 37.5
With .FormatConditions
.Delete: .Add Type:=2, Formula1:="=MOD(LIGNE()+COLONNE();2)"
End With
.FormatConditions(1).Interior.ColorIndex = 1: .BorderAround 1, 4, 23
End With
End Sub
Si il y a d'autres exemples je suis preneur.
Sub damier2()
Dim c As Range
For Each c In [A1:J10]
If c.Row Mod 2 Xor c.Column Mod 2 Then
c.Interior.ColorIndex = 4 - c.Row Mod 2
' ou
' c.Interior.ColorIndex = 1
End If
Next c
End Sub
Bonjour JBARBE.
Est-ce pour une question de lisibilté que tu démarre i à partir de 15 ?
Sub Damier1()
Dim xcell As Range
Application.ScreenUpdating = False
Range("A1:J10").Interior.ColorIndex = 0
Range("B1").Interior.ColorIndex = 3
Range("A2").Interior.ColorIndex = 4
For Each xcell In Range("A1:J10")
xcell.Interior.ColorIndex = Cells((xcell.Row - 1) Mod 2 + 1, (xcell.Column - 1) Mod 2 + 1).Interior.ColorIndex
Next xcell
Application.ScreenUpdating = True
End Sub
Sub Damier2()
Dim i&, j&
Application.ScreenUpdating = False
Range("A1:J10").Interior.ColorIndex = 0
Range("B1").Interior.ColorIndex = 3
Range("A2").Interior.ColorIndex = 4
For i = 0 To 9
For j = 0 To 9
Cells(i + 1, j + 1).Interior.ColorIndex = Cells(i Mod 2 + 1, j Mod 2 + 1).Interior.ColorIndex
Next j
Next i
Application.ScreenUpdating = True
End Sub
Range("A1").Interior.ColorIndex = 5
Range("B2").Interior.ColorIndex = 6
=ET(MOD(LIGNE();2)=1;MOD(COLONNE();2)=0)
=ET(MOD(LIGNE();2)=0;MOD(COLONNE();2)=1)