我认为我的For
IF
和Next
语句的顺序有问题,我试图只突出显示满足所有条件的行,相反,当我的代码使其突出显示的部分所有行都单独突出显示,代码似乎运行速度很慢,我相信我执行了太多迭代?迭代次数过多:仅在满足所有条件后突出显示单元行所需的语法
Sub SWAPS100()
Dim rng As Range, lCount As Long, LastRow As Long
Dim cell As Object
Sheets("Output").Activate
With ActiveSheet
LastRow = .Cells(Rows.Count, 1).End(xlUp).Row
For Each cell In .Range("E2:E" & LastRow) 'new position
If cell = "N" Then
Debug.Print
For Each cell1 In .Range("U2:U" & LastRow) 'Secuirty type
If cell1 = "SW" Then
For Each cell2 In .Range("J2:J" & LastRow) 'prior px
If cell2 = 100 Then
For Each cell3 In .Range("I2:I" & LastRow) 'current px
If cell3 <> 100 Then
'With cell.Interior
With cell.EntireRow.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 6382079
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next cell3
End If
Next cell2
End If
Next cell1
End If
Next cell
End With
为什么不使用[AND](http://stackoverflow.com/questions/9140318/how-to-use-and-in-if-statement-vba)?除非满足所有条件,否则你似乎没有做任何事情。 – Raystafarian