Comparaison de 2 plage

Fermé
Eddie - 16 févr. 2011 à 19:18
Bonjour, je compare 2 plages et la plage #2 doit avoir de la couleur pour les cellules qui on des valeurs identique à la plage #1. voici mon code, j,ai un message d'erreur à la ligne .color= vbred

Private Sub Workbook_Open()
Dim CompareRange_1 As Variant, x As Variant, y As Variant, CompareRange_2 As Variant
' Set CompareRange equal to the range to which you will
' compare the selection.
Set CompareRange_1 = Range("b3:g36")
Set CompareRange_2 = Range("j3:036")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
' Set CompareRange = Workbooks("Book2"). _
' Worksheets("Sheet2").Range("C1:C5")
'
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.
For Each x In CompareRange_2
For Each y In CompareRange_1
If x = y Then x.Font
.Color = vbRed
.Bold = True
Next y
Next x
End Sub


merci