M
M
Maratka2016-10-25 10:50:25
excel
Maratka, 2016-10-25 10:50:25

How to select all cells with style?

How to highlight all cells with "bad" style in excel? And sum them up

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Fedoryan, 2016-10-25
@mopaad

Sub SumBad()
    Dim WK As Workbook
    Dim WS As Worksheet
    Dim Bad_Sum As Integer
    
    Set WK = Excel.ActiveWorkbook
    Set WS = WK.ActiveSheet
    
    Bad_Sum = 0
    ' Перебор строк
    For r = 2 To 7
        ' Перебор столбцов
        For c = 6 To 8
            If WS.Cells(r, c).Style = "Плохой" And IsNumeric(WS.Cells(r, c)) Then
                Bad_Sum = Bad_Sum + WS.Cells(r, c)
            End If
        Next c
    Next r
    
    ' Вывод результата
    WS.Cells(9, 6) = Bad_Sum
End Sub

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question