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
| Private Sub Worksheet_Calculate()
Const nbf = 8 ' nombre de formats à adapter
Dim idx As Integer, tdc As Long
[B14].Value = [A2].Value
tdc = Application.Calculation
Application.Calculation = xlCalculationManual
ReDim cdf(1 To nbf, 1 To 3)
If [F1] <> "" Then
idx = idx + 1: cdf(idx, 1) = "B4": cdf(idx, 2) = "F1"
cdf(idx, 3) = InStr(Range(cdf(idx, 1)), Range(cdf(idx, 2)))
End If
If [F1] <> "" Then
idx = idx + 1: cdf(idx, 1) = "B14": cdf(idx, 2) = "F1"
cdf(idx, 3) = InStr(Range(cdf(idx, 1)), Range(cdf(idx, 2)))
End If
If [F2] <> "" Then
idx = idx + 1: cdf(idx, 1) = "B14": cdf(idx, 2) = "F2"
cdf(idx, 3) = InStr(Range(cdf(idx, 1)), Range(cdf(idx, 2)))
End If
If [F3] <> "" Then
idx = idx + 1: cdf(idx, 1) = "B14": cdf(idx, 2) = "F3"
cdf(idx, 3) = InStr(Range(cdf(idx, 1)), Range(cdf(idx, 2)))
End If
For idx = 1 To UBound(cdf)
If cdf(idx, 1) <> "" Then
With ActiveSheet.Range(cdf(idx, 1)).Font
.Color = 0 ' noir
.Bold = False 'gras
.Size = 11
End With
End If
Next idx
For idx = 1 To UBound(cdf)
If cdf(idx, 1) <> "" And cdf(idx, 3) > 0 Then
With ActiveSheet.Range(cdf(idx, 1)).Characters(cdf(idx, 3), Len(Range(cdf(idx, 2)))).Font
.ColorIndex = 3 'rouge
.Bold = True 'gras
.Size = 20
End With
End If
Next idx
Application.Calculation = tdc
End Sub |
Partager