在以下代码中,即使两个变量不同,也会发生else条件。如果我删除它,它就可以正常工作,但有空白点,应该写“否”。
For i = 2 To lRowMas 'Loop through all rows in Master Sheet
For j = 2 To lRowCurrentSheet 'Loop through all rows in sheet to compare
If Sheets(masterSheet).Cells(i, 1) = Sheets(sheetNamesAsArray(x)).Cells(j, 1) Then
Sheets(masterSheet).Cells(i, x + 2).Value = "Yes" 'set value to Yes
Else
Sheets(masterSheet).Cells(i, x + 2).Value = "No" 'set value to Yes
End If
Next j 'End inner loop, on sheet to compare
Next i 'End outer loop, on MasterSheet
答案 0 :(得分:1)
我解决了我的问题。我忘了添加一个End For,所以一旦找到匹配并写入yes,它将在下一次迭代中覆盖它。谢谢大家的意见。