Find Italics in a named range excel 2010 vba then add values to a variable and output to form control

StackOverflow https://stackoverflow.com/questions/21245104

  •  30-09-2022
  •  | 
  •  

Domanda

I am trying to search each cell individually in a named range and find each cell that has italic font. If the font is italic then I would like to add that cell's number to a variable so I can get a total.

Any help is much appreciated.

Justin

È stato utile?

Soluzione

You are looking for the .Font.Italic property. Test the following. Modify accordingly.

Sub AddItalicizedNums()
    Dim TargetRng As Range, Cell As Range
    Dim SumOfItalics
    Set TargetRng = Range("OneToTwenty")
    SumOfItalics = 0
    For Each Cell In TargetRng
        If Cell.Font.Italic = True Then
            SumOfItalics = SumOfItalics + Cell.Value
        End If
    Next Cell
    MsgBox SumOfItalics
End Sub

Screenshot:

enter image description here

My named range is OneToTwenty and I italicized (and boldfaced) all even numbers in it. The sum is showing correctly, as shown in the message box.

Let us know if this helps.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top