111.jpg
如題铅匹,要求統(tǒng)計(jì)和求和所有“N”字符
思路:
? 循環(huán)遍歷數(shù)據(jù)區(qū)域酷宵,步長(zhǎng)值為2钩乍,然后依次與“N”進(jìn)行判斷
細(xì)節(jié):
? 各個(gè)數(shù)據(jù)小的數(shù)據(jù)區(qū)域塊之間有一行空白溺拱,所以對(duì)該行需要處理
代碼:
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) = "個(gè)數(shù)為:" & c
Cells(3, max_c + 2) = "個(gè)數(shù)為:" & s
End Sub
效果:
222.jpg