行值更改时,在多行和多列EXCEL中着色单元格

时间:2016-03-21 22:12:48

标签: excel vba scripting formatting

我需要能够

- 比较每列的行数据(从单元格B2到结尾,即整个工作表减去第一行和第一列)

- 如果所述列中没有数据变化;然后突出显示列标题

- 如果数据发生变化;突出显示数据正在变化的第一个单元格

请参阅示例,请记住我拥有的excel表格要大得多,就像巨大的,所以使用参考列不会工作,每列的多个公式也不会工作。我发现这个单列很好,=间接(" A"& ROW())<> INDIRECT(" A"&(ROW() - 1) ),但我无法将其应用于100多列,不实用。请帮忙。

enter image description here enter image description here

Bahh,我自己写了一个,它对行数或列数没有动态,但它完成了工作,我想我不必经历行和列,但我不能&# 39; t弄清楚如何以足够快的速度参考细胞位置。比RobB更好的解决方案,拍打他的牙龈。

Private Sub CommandButton1_Click()
Dim i As Long
Dim j As Long
Dim flag As Boolean
Columns().Font.Color = vbBlack
Rows().Interior.ColorIndex = 0
flag = False
For j = 2 To 120 'Must hard code number of columns
    For i = 3 To 3300 'Must hard code numbe of rows
        If Cells(i, j).Value <> Cells(i - 1, j) And Not IsEmpty(Cells(i, j).Value) Then
            Cells(i, j).Interior.ColorIndex = 37
            flag = True
        Else
            If flag Then
                Cells(1, j).Interior.ColorIndex = 36
            End If
        End If

    Next i
    flag = False
Next j
End Sub

1 个答案:

答案 0 :(得分:-1)

对于宏来说,这听起来像是一项简单的任务 - 尽管这需要您手动执行某些操作(例如按键)以启动比较。