我有一系列的单元格从列CA开始,然后转到CX,我需要做的是计算该范围内一次只有一行的单元格数量,这些单元格的值不是0。
答案 0 :(得分:0)
这对你有用。您需要根据数据更改循环范围
Sub CountValues()
Dim lcell As Range
Dim c_row As Long
Dim values_counter As Long
c_row = 0
For Each lcell in Range("$CA$2","$CX$100")
If lcell.row <> c_row then
values_counter = 0
c_row = lcell.row
End If
If lcell.value <> 0 Then
values_counter = values_counter + 1
End If
If lcell.Column = Cells(1, "CX").Column Then
'Do Something with values_counter here
End If
Next lcell
End Sub