第1个回答 2016-02-22
Sub s()
Set rg = [k:q]
c = 20
x = rg.Column
y = x + rg.Columns.Count - 1
n = Cells(Rows.Count, x).End(3).Row
For i = n To n - c + 1 Step -1
If i = 1 Then Exit For
f = True
For j = x To y
If Cells(i, j) = Cells(i - 1, j) Then
f = False
Cells(i, j).Interior.ColorIndex = 7
End If
Next
If f Then Range(Cells(i, x), Cells(i, y)).Interior.ColorIndex = 6
Next
End Sub本回答被提问者和网友采纳
第2个回答 2016-03-02
VBA代码如下:
Sub s()
Set rg = [k:q]
c = 20
x = rg.Column
y = x + rg.Columns.Count - 1
n = Cells(Rows.Count, x).End(3).Row
For i = n To n - c + 1 Step -1
If i = 1 Then Exit For
f = True
For j = x To y
If Cells(i, j) = Cells(i - 1, j) Then
f = False
Cells(i, j).Interior.ColorIndex = 7
End If
Next
If f Then Range(Cells(i, x), Cells(i, y)).Interior.ColorIndex = 6
Next
End Sub
第3个回答 2016-02-24
Range("A1:A2").Interior.ColorIndex = 3
类似这种,只需要去更改range区域即可!