Hi, i changed the code, it s a lot easier to understand that way, it looks like the Elseif doesn t apply when i encounter letters in a cell, so i get an error type mismatch in those case and i just wanted the code to color cells that have letters in colorindex 5...
hope some1 can help, thank you
If NumberButton Then
'fonction if au cas où inverse est coché
If CheckBox1.Value = True Then
For Each vCellules2 In Range(RefEdit2.Value)
For Each vCellules1 In Range(RefEdit1.Value)
vCellules1.Replace _
What:=" ", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
vCellules2.Replace _
What:=" ", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
If vCellules1.Interior.ColorIndex = xlNone _
And vCellules2.Interior.ColorIndex = xlNone _
And IsNumeric(vCellules1) = True _
And IsNumeric(vCellules2) = True _
And (vCellules1.Value - (vCellules2.Value * -1)) <= (CDbl(TextBox1.Value)) _
And ((vCellules2.Value * -1) - (vCellules1.Value)) <= (CDbl(TextBox1.Value)) _
And vCellules1.Text <> "" _
And vCellules1.Address <> vCellules2.Address Then
vCellules1.Interior.Color = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
vCellules2.Interior.Color = vCellules1.Interior.Color
ElseIf IsNumeric(vCellules1) = False Or IsNumeric(vCellules2) = False Then
vCellules1.Interior.ColorIndex = 5
vCellules2.Interior.ColorIndex = 5
End If
Next vCellules1
Next vCellules2
Else
'Else du CheckBox1 donc si inverse non coché
For Each vCellules2 In Range(RefEdit2.Value)
For Each vCellules1 In Range(RefEdit1.Value)
vCellules1.Replace _
What:=" ", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
vCellules2.Replace _
What:=" ", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True
If vCellules1.Interior.ColorIndex = xlNone _
And vCellules2.Interior.ColorIndex = xlNone _
And IsNumeric(vCellules1) = True _
And IsNumeric(vCellules2) = True _
And (vCellules1.Value - (vCellules2.Value)) <= (CDbl(TextBox1.Value)) _
And ((vCellules2.Value) - (vCellules1.Value)) <= (CDbl(TextBox1.Value)) _
And vCellules1 <> "" _
And vCellules2 <> "" _
And vCellules1.Address <> vCellules2.Address Then
vCellules1.Interior.Color = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
vCellules2.Interior.Color = vCellules1.Interior.Color
ElseIf IsNumeric(vCellules1) = False Or IsNumeric(vCellules2) = False Then
vCellules1.Interior.ColorIndex = 5
vCellules2.Interior.ColorIndex = 5
End If
Next vCellules1
Next vCellules2
End If
End If
Unload MatchingMacro
End Sub
Bookmarks