excel vba填充单元(自动填充)

c:i列
相连两列之间对比
A("左"列上单元对"右"列下单元)
B("右"列上单元对"左"列下单元)

Sub xx()
    For Each c In [d14:h23]
        If c Mod 5 = c.Offset(-1, -1) Mod 5 Then c.Interior.ColorIndex = 3
        If c Mod 5 = c.Offset(-1, 1) Mod 5 Then c.Interior.ColorIndex = 7
    Next
End Sub追问

从C14到I最后结束
不要执行代码,自动填充(将代码放到表的模块哪种)

追答Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    For Each c In [c14].CurrentRegion
        If c <> "" And IsNumeric(c) Then
            If c.Offset(-1, -1) <> "" And IsNumeric(c.Offset(-1, -1)) Then If c Mod 5 = c.Offset(-1, -1) Mod 5 Then c.Interior.ColorIndex = 3
            If c.Offset(-1, 1) <> "" And IsNumeric(c.Offset(-1, 1)) Then If c Mod 5 = c.Offset(-1, 1) Mod 5 Then c.Interior.ColorIndex = 7
        End If
    Next
End Sub追问

代码粘到表的模块了
但是没有变化呢?

追答
温馨提示:答案为网友推荐,仅供参考
相似回答