我B列都是数字,现在我要一段代码,执行之后,把B(X)=5 , B(X+1)=8 , B(X+2)=12 把满足条件的三行标记颜色
Sub fdas()
Dim n%, i%, rng As Range
n = Range("B65536").End(3).Row
For i = 1 To n
If Cells(i, 2) = 5 And Cells(i + 1, 2) = 8 And Cells(i + 2, 2) = 12 Then
If rng Is Nothing Then
Set rng = Range(Cells(i, 2), Cells(i + 2, 2))
Else
Set rng = Union(rng, Range(Cells(i, 2), Cells(i + 2, 2)))
End If
i = i + 2
End If
Next
rng.Interior.ColorIndex = 3
End Sub
Dim n%, i%, rng As Range
n = Range("B65536").End(3).Row
For i = 1 To n
If Cells(i, 2) = 5 And Cells(i + 1, 2) = 8 And Cells(i + 2, 2) = 12 Then
If rng Is Nothing Then
Set rng = Range(Cells(i, 2), Cells(i + 2, 2))
Else
Set rng = Union(rng, Range(Cells(i, 2), Cells(i + 2, 2)))
End If
i = i + 2
End If
Next
rng.Interior.ColorIndex = 3
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答 2012-04-18
Sub aa()
Application.ScreenUpdating = False
For i = 1 To Range("b65536").End(3).Row - 2
If Cells(i, 2) = 5 And Cells(i + 1, 2) = 8 And Cells(i + 2, 2) = 12 Then
Cells(i, 2).Resize(3, 1).Font.ColorIndex = 3
End If
Next
Application.ScreenUpdating = True
End Sub
Application.ScreenUpdating = False
For i = 1 To Range("b65536").End(3).Row - 2
If Cells(i, 2) = 5 And Cells(i + 1, 2) = 8 And Cells(i + 2, 2) = 12 Then
Cells(i, 2).Resize(3, 1).Font.ColorIndex = 3
End If
Next
Application.ScreenUpdating = True
End Sub