如题,要求统计和求和所有“N”字符
思路:
循环遍历数据区域,步长值为2,然后依次与“N”进行判断
细节:
各个数据小的数据区域块之间有一行空白,所以对该行需要处理
代码:
Sub t()
Dim max_r!, max_c!, x!, y!, s As Long, c!
max_r = [b66356].End(xlUp).Row
max_c = [b2].End(xlToRight).Column
For x = 2 To max_r Step 2
If Cells(x, 2) = "" Then x = x + 1
For y = 2 To max_c
With Cells(x, y)
If .Value = "N" Then
s = s + .Offset(1, 0).Value
c = c + 1
End If
End With
Next y
Next x
Cells(2, max_c + 2) = "个数为:" & c
Cells(3, max_c + 2) = "个数为:" & s
End Sub
网友评论