【发布时间】:2019-02-15 13:49:12
【问题描述】:
此代码根据单元格颜色“绿色”进行计算。不幸的是,当它到达下一行时,例如“E”行(如图所示)计算不是单独进行的,例如仅适用于 C 行,但它采用 C 行中的值,如图所示。如何重写代码,使计算只逐行进行?
Sub Schaltfläche1_Klicken()
Dim wb As Workbook, wq As Object
Dim ws As Worksheet, datDatum
Dim cell As Range
Dim c As Long, r As Long, rng As Range
With Worksheets("Tabelle1")
For c = 3 To 5
For r = 1 To 5
If .Cells(r, c).DisplayFormat.Interior.Color = vbRed Then
If rng Is Nothing Then
Set rng = .Cells(r, c)
Else
Set rng = Union(rng, .Cells(r, c))
End If
End If
Next r
If Not rng Is Nothing Then _
.Cells(8, c).Formula = "=average(" & rng.Address(0, 0) & ")"
Next c
End With
End Sub
【问题讨论】:
-
为编辑干杯
标签: excel vba colors conditional cell