excel vba判断奇数偶数

1。判断连续3个以上的奇数(填充单元格为黄色)或偶数(填充单元格为青色)
2。K:Z列(从列最下开始往上填充)
3。判断连续3个以上的奇数,遇偶数时停止填充颜色(填充单元格为黄色)
4。判断连续3个以上的偶数,遇奇数时停止填充颜色(填充单元格为青色)

Sub xx()
    For i = 11 To 26
        n = Cells(4 ^ 8, i).End(3).Row
        ji = 0
        ou = 0
        Do While Cells(n, i) <> "" And IsNumeric(Cells(n, i))
            If Cells(n, i) Mod 2 = 0 Then
                If ji >= 3 Then Cells(n + 1, i).Resize(ji).Interior.ColorIndex = 6
                ji = 0
                ou = ou + 1
            Else
                If ou >= 3 Then Cells(n + 1, i).Resize(ou).Interior.ColorIndex = 8
                ou = 0
                ji = ji + 1
            End If
            n = n - 1
            If n = 0 Then Exit Do
        Loop
        If ji >= 3 Then Cells(n + 1, i).Resize(ji).Interior.ColorIndex = 6
        If ou >= 3 Then Cells(n + 1, i).Resize(ou).Interior.ColorIndex = 8
    Next
End Sub追问

2。K:Z列(从列最下开始往上填充)
3。(从列最下开始往上填充,当列最后一个不填充时,此列不再填充颜色)

追答Sub xx()
    For i = 11 To 26
        n = Cells(4 ^ 8, i).End(3).Row
        ji = 0
        ou = 0
        Do While Cells(n, i) <> "" And IsNumeric(Cells(n, i))
            If Cells(n, i) Mod 2 = 0 Then
                If ji < 3 Then
                    ou = ou + 1
                    ji = 0
                Else
                    Exit Do
                End If
            Else
                If ou < 3 Then
                    ji = ji + 1
                    ou = 0
                Else
                    Exit Do
                End If
            End If
            n = n - 1
            If n = 0 Then Exit Do
        Loop
        If ji >= 3 Then Cells(n + 1, i).Resize(ji).Interior.ColorIndex = 6
        If ou >= 3 Then Cells(n + 1, i).Resize(ou).Interior.ColorIndex = 8
    Next
End Sub
温馨提示:答案为网友推荐,仅供参考
相似回答