代码:
Sub aa()
Dim a As Range
Dim b As Range
For Each a In Range("a1:a10")
For Each b In Range("b1:b10")
If a = "Saran" And b = "Raj" Then
a.Offset(0, 2) = "Correct"
Else
a.Offset(0, 2) = "InCorrect"
End If
Next
Next
End Sub
输出:
Saran Raj Correct
Saran Raj Correct
Saran Raj Correct
Saran Mohan InCorrect
Saran Mohan InCorrect
Saran Mohan InCorrect
Saran Mohan InCorrect
Saran Raj Correct
Saran Raj Correct
Saran Raj Correct
答案 0 :(得分:1)
假设"输出"实际上并不是你得到的输出,但认为你应该得到的输出,问题是For Each b In Range("b1:b10")
的最后一次迭代正在查看"Raj"
中的Range("B10").Value
值。由于每个a.Value
值均为"Saran"
,因此,在最后b
次迭代中,a.Value
"Saran"
和{{1 } b.Value
,因此您应该获得每行中C列"Raj"
的答案。
我想你想要
"Correct"