Есть функция, взята с Планеты:
работает, все отлично. Ее надо перенести в макрос.
Ругается на цикл, хотя я его не трогал, говорит invalid next control variable reference, помогите пожалуйста
| Код |
|---|
Public Function SumByColor(DataRange As Range, ColorSample As Range) As Double Dim Sum As Double Application.Volatile True For Each cell In DataRange If cell.Interior.Color = ColorSample.Interior.Color Then Sum = Sum + cell.Value End If Next cell SumByColor = Sum End Function |
| Код |
|---|
Sub SumByColor()
Dim rData As Range
Dim cellRefColor As Range
Dim Sum, SumByColor As Double
Dim indRefColor As Long
Dim cellCurrent As Range
rData = InputBox("Âûáåðèòå ñòîëáåö ñóììèðîâàíèÿ.")
cellRefColor = InputBox("Âûáåðèòå ÿ÷åéêó ñ öâåòîì, ïî êîòîðîìó áóäåò ñóììèðîâàíèå")
indRefColor = cellRefColor.Cells(1, 1).Interior.Color
Application.Volatile True
For Each ñellCurrent In rData
If indRefColor = ñellCurrent.Interior.Color Then
Sum = WorksheetFunction.Sum(cellCurrent, Sum)
End If
Next cellCurrent
ActiveCell.Value = Sum
End Sub
|
Изменено: - 09.02.2018 14:40:17