1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| Sub color_cells()
Dim t1 As String
Dim t2 As String
Dim t3 As String
Dim wso As Worksheet
Dim Lig As Long, Col As Integer
Set wso = Worksheets("Resultats")
wso.UsedRange.Font.ColorIndex = 1
'Détermine la dernière ligne renseignée de la feuille de calculs
Col = wso.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Column
'Détermine la dernière colonne renseignée de la feuille de calculs
Lig = wso.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
For count1 = 2 To Lig
For count2 = 3 To Col
textst = Range(Cells(count1, count2), Cells(count1, count2)).Value
x = InStr(1, textst, "_")
If textst = "" Or x = 0 Then
Else
TabElement = Split(textst, "_")
t1 = TabElement(0)
t2 = TabElement(1)
t3 = TabElement(2)
t4 = TabElement(3)
aString = t1
lga = Len(aString)
bString = t2
lgb = Len(bString)
CString = t3
lgt = lga + lgb + 2
Dstring = t4
lgd = Len(Dstring) + 2
Cells(count1, count2).Value = aString & "_" & bString & "_" & CString & "_" & Dstring
With Cells(count1, count2)
.Font.ColorIndex = 5
.Characters(1, Len(aString)).Font.ColorIndex = 30
.Characters(lgt, Len(CString) + lgd).Font.ColorIndex = 10
End With
End If
Next count2
Next count1
End Sub |
Partager