如何使用IF语句循环遍历工作表,并将每个语句TRUE附加到数组中?
基本示例,如果Cells(y, 1).Value大于 0,则将 1 追加到数组中,并通过给定范围创建具有多个 1 值的数组(给定多个 Cells(y, 1).Value(s) 大于 0)。
这就是我之前创建循环的方式。
For y = 2 To LastRow
On Error Resume Next
If Cells(y, 1).Value > 0 Then
Cells(y, 2).Value = 1 ' Instead of populating Cells(y,2) with "1" IF true, I want to append the value to an array
ElseIf Cells(y, 1).Value = 0 > 0 Then
Cells(y, 2).Value = 2
Else
Cells(y, 2).Value = 0
End If
Next y
Run Code Online (Sandbox Code Playgroud)