我有以下nexted for循环excel vba:为什么不嵌套for循环做1到多重比较?
'searches matches in Col C against B
For Row = 2 to totalrows Step 1
'MsgBox "cell :" & Cells(Row, 2).Value
For c = 2 To totalrows Step 1
MsgBox " cell b :" & Cells(c, 2) & " cell C:" & Cells(rows, 3).Value
If Cells(c, 3).Value = Cells(Row, 2).Value Then
'change b color to orange = found
With Cells(c, 2).Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
End If
Next c
Next Row
现在它比较 B1 = C1 B2 = C2 B3 = C3的 代替 B1 = C1 B1 = C2 B1 = C3 B2 = c1 b2 = c2 ...
我错过了什么吗?
在msgbox中,当你得到单元格b的值时,你错过了.value,并且当你得到单元格c的值时,你写入的单元格(行,3)是错误的,应该是单元格(行,3) – BlackBear 2010-12-13 21:11:40