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 52 53 54
|
Sub test()
Dim i As Long
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Sheet1") ' Sheet1 à remplacer par le nom de la feuille
For i = 1 To ws.Cells(Rows.Count, 1).End(xlUp).Row Step 2
Select Case CountCharacter(ws.Cells(i, 1).value, ".")
Case 0 ' la cellule ne compte pas de "."
Case 1 ' la cellule compte un seul "."
ws.Range(Cells(i, 1), Cells(i + 1, 1)).Font.FontStyle = "Bold"
Case 2 ' la cellule compte un deux "."
ws.Range(Cells(i, 1), Cells(i + 1, 1)).Font.FontStyle = "Italic"
Case 3 ' la cellule compte trois "."
ws.Range(Cells(i, 1), Cells(i + 1, 1)).Font.FontStyle = "Bold Italic"
Case Else ' Autre cas msg d'alerte
MsgBox "Attention , la cellule A" & i & " compte " & CountCharacter(Cells(i, 1).value, ".") & " points ce cas de figure n'a pas été codé."
End Select
Next i
Set ws = Nothing
Set wb = Nothing
End Sub
Function CountCharacter(strText As String, strFind As String, _
Optional lngCompare As VbCompareMethod) As Long
' Fonction permettant de compté le nombre de fois ou un caractère ( strFind) se trouve dans la chaine de caract (strText)
Dim lngPos As Long
Dim lngTemp As Long
Dim lngCount As Long
If Len(strText) = 0 Then Exit Function
If Len(strFind) = 0 Then Exit Function
lngPos = 1
Do
lngPos = InStr(lngPos, strText, strFind, lngCompare)
lngTemp = lngPos
If lngPos > 0 Then
lngCount = lngCount + 1
lngPos = lngPos + Len(strFind)
End If
Loop Until lngPos = 0
CountCharacter = lngCount
End Function |
Partager