Private Const PAR_OUV As String = "("
Private Const PAR_FER As String = ")"
Public Sub ColorizeParenthese(ByRef Cell2Colorize As Range)
Dim i As Long
Dim tabCol() As Long
Dim ColIndex As Integer
For i = 1 To Len(CStr(Cell2Colorize.Value))
Select Case Mid(CStr(Cell2Colorize.Value), i, 1)
Case PAR_OUV
If ColIndex = 0 Then
ColIndex = ColIndex + 6
ReDim tabCol(0)
tabCol(0) = ColIndex
Else
If ColIndex > 53 Then ColIndex = 0
ColIndex = ColIndex + 4
ReDim Preserve tabCol(UBound(tabCol) + 1)
tabCol(UBound(tabCol)) = ColIndex
End If
Cell2Colorize.Characters(i, 1).Font.ColorIndex = tabCol(UBound(tabCol))
Case PAR_FER
Cell2Colorize.Characters(i, 1).Font.ColorIndex = tabCol(UBound(tabCol))
If UBound(tabCol) <> 0 Then ReDim Preserve tabCol(UBound(tabCol) - 1)
End Select
Next i
Erase tabCol
End Sub
Sub Exemple_Utilisation()
Call ColorizeParenthese([A1])
End Sub