excel vba填充单元格颜色(求助各位大师)

2025-04-04 07:19:14
推荐回答(1个)
回答1:

Sub TianChong()
    Dim i As Long, iCol As Long, iRow As Long
    i = Cells(Cells.Rows.Count, "K").End(xlUp).Row
    Range("K28:Z" & i).Interior.ColorIndex = 0
    
    For iCol = 11 To 26
        For iRow = i To 29 Step -1
            If Cells(iRow, iCol).Value <> "" Then
                If Cells(iRow, iCol).Value = Cells(iRow - 1, iCol).Value Then
                    Cells(iRow - 1, iCol).Resize(2, 1).Interior.ColorIndex = 6
                End If
            End If
        Next iRow
    Next iCol
End Sub