我想知道为什么这段代码根本不打印1。我知道0会覆盖arr_bed变量。但是,我如何使代码可以区分为0和1?谢谢!
For n = 3 To time_frame + 3
For i = 3 To 1002
If (Cells(i, "U").Value = Cells(n, "X").Value) Then
arr_bed = 1 ' admission (HH)
Else
arr_bed = 0
Cells(n, "Y").Value = arr_bed
End If
Next i
Next n
答案 0 :(得分:0)
您需要在找到它时退出for并将输出移出内部循环:
For n = 3 To time_frame + 3
arr_bed = 0
For i = 3 To 1002
If (Cells(i, "U").Value = Cells(n, "X").Value) Then
arr_bed = 1
Exit For ' admission (HH)
End If
Next i
Cells(n, "Y").Value = arr_bed
Next n
另一个注意事项:你应该对表格进行限定(没有看到其余的代码,我不想假设如何为你做这些)。