请求大神帮忙改一下EXCEL的VBA

Sub 连续标志奇偶()
Dim R As Integer, i As Integer, bz As Integer, num As Integer
R = ActiveSheet.Range("A65536").End(xlUp).Row
bj = Range("a1").Value Mod 2: num = 1
For i = 2 To R
If bj = Cells(i, 1) Mod 2 Then num = num + 1 Else bj = Cells(i, 1) Mod 2: num = 1
If num >= 6 Then Cells(i, 2) = Str(num)
Next i
End Sub
请大神帮忙改为连续6个或以上的偶数才标示,奇数不标示,谢谢

Sub 连续偶()
Dim R As Integer, i As Integer, bz As Integer, num As Integer
    R = ActiveSheet.Range("A65536").End(xlUp).Row
    For i = 2 To R
        If Cells(i, 1) Mod 2 = 0 Then num = num + 1 Else num = 0
        If num >= 6 Then Cells(i, 2) = Str(num)
    Next i
End Sub

追问

这个是可以做到连续的六个或以上偶数标示,但为什么在我在手动打字上去的能标示,而用公式自动计算的数据无法标示,比如我在A1输入公式=IF(C1=D1,1,"")向下拉,这样的出来连续六个空格时VBA没法标6

追答

空格 又不是数字,
=IF(C1=D1,1,0)

你写成 0 就是数字了

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-06-30
If bj = Cells(i, 1) Mod 2 Then num = num + 1 Else bj = Cells(i, 1) Mod 2: num = 1



If bj = Cells(i, 1) Mod 2 Then
num = num + 1
Else
bj = Cells(i, 1) Mod 2
num = 1
end if追问

奇数的还是会标出来,请帮忙把奇数的标示删掉,谢谢

追答

If bj = Cells(i, 1) Mod 2 Then num = num + 1 Else bj = Cells(i, 1) Mod 2: num = 1



If Cells(i, 1) Mod 2=0 Then
num = num + 1
Else
num = 1
end if

本回答被网友采纳
相似回答