Computer‎ > ‎Blog‎ > ‎

[Excel-VBA] Zählen, wenn Fett/Kursiv ua.

veröffentlicht um 29.11.2015, 02:35 von Erhard Rainer   [ aktualisiert: 29.11.2015, 02:40 ]
Kürzlich stand ich vor dem Problem, nur die Zellen zählen zu wollen, die eine bestimmte Formatierung aufweisen.
Anbei die Funktionen:
  • Zählen, wenn Fett/Bold = CountBold

CountBold

Public Function CountBold(myRange As Range) As Integer
Dim i As Integer
Dim j As Integer
Dim BoldCounter As Integer
With myRange
    For i = 1 To myRange.Rows.Count
        For j = 1 To myRange.Columns.Count
            If .Cells(i, j).Font.Bold = True And .Cells(i, j).Value <> "" Then
                BoldCounter = BoldCounter + 1
            End If
        Next j
    Next i
End With
CountBold = BoldCounter
End Function
  • Zählen, wenn Kursiv/Italic = CountItalic

CountItalic

Public Function CountItalic(myRange As Range) As Integer
Dim i As Integer
Dim j As Integer
Dim ItalicCounter As Integer
With myRange
    For i = 1 To myRange.Rows.Count
        For j = 1 To myRange.Columns.Count
            If .Cells(i, j).Font.Italic = True And .Cells(i, j).Value <> "" Then
                ItalicCounter = ItalicCounter + 1
            End If
        Next j
    Next i
End With
CountItalic = ItalicCounter
End Function
  • Zählen, wenn Fett/Bold und Kursiv/Italic = CountItalicBold

CountItalicBold

Public Function CountItalicBold(myRange As Range) As Integer
Dim i As Integer
Dim j As Integer
Dim ItalicBoldCounter As Integer
With myRange
    For i = 1 To myRange.Rows.Count
        For j = 1 To myRange.Columns.Count
            If .Cells(i, j).Font.Italic = True And .Cells(i, j).Font.Bold = True And .Cells(i, j).Value <> "" Then
                ItalicBoldCounter = ItalicBoldCounter + 1
            End If
        Next j
    Next i
End With
CountItalicBold = ItalicBoldCounter
End Function

Comments