Curious, why it works in mine?I believe COUNTIF does not work with arrray...
Try this:
=IF(OR(array=0), do this, do that)
Because thisCurious, why it works in mine?
View attachment 76713
I though OP want "Dynamic arrays from range" not "Dynamic range".i am creating Dynamic arrays from ranges and need to check if it contains a zero, if it does do this, else do that..
whats the best way to test if a returned dynamic array contains a zero? thanks
Sub Test_For_Zero()
Dim Arr, i As Long, j As Long, k As Long
Arr = Range("A1", Cells(Rows.Count, "B").End(xlUp)) '<< change range to suit
For i = 1 To UBound(Arr, 1)
For j = 1 To UBound(Arr, 2)
If Arr(i, j) = 0 Then
k = k + 1
End If
Next j
Next i
If k > 0 Then
'Do something
Else
'Do something else
End If
End Sub
Why do not stop right after zero found?One possibility
VBA Code:Sub Test_For_Zero() Dim Arr, i As Long, j As Long, k As Long End Sub
Sub Test_For_Zero()
Dim Arr, i As Long, j As Long, k As Long
Arr = Range("A1", Cells(Rows.Count, "B").End(xlUp)) '<< change range to suit
For i = 1 To UBound(Arr, 1)
For j = 1 To UBound(Arr, 2)
If Arr(i, j) = 0 Then
Do something
Exit sub
End If
Next j
Next i
Do something else
End Sub
Sub Test_For_Zero()
Dim Arr, i As Long, j As Long, k As Long
Arr = Range("A1", Cells(Rows.Count, "B").End(xlUp)) '<< change range to suit
If not Arr.Find 0 is nothing then
Do something
else
Do Something else
end if
end sub
@bebo021999 yes, good point!Why do not stop right after zero found?
Or using FIND should be simplerVBA Code:Sub Test_For_Zero() Dim Arr, i As Long, j As Long, k As Long Arr = Range("A1", Cells(Rows.Count, "B").End(xlUp)) '<< change range to suit For i = 1 To UBound(Arr, 1) For j = 1 To UBound(Arr, 2) If Arr(i, j) = 0 Then Do something Exit sub End If Next j Next i Do something else End Sub
VBA Code:Sub Test_For_Zero() Dim Arr, i As Long, j As Long, k As Long Arr = Range("A1", Cells(Rows.Count, "B").End(xlUp)) '<< change range to suit If not Arr.Find 0 is nothing then Do something else Do Something else end if end sub
just using the COUNTIF(A1#,0)... this works in a direct formula against a dynamic array like you show in your example and i tested with Sequence()Excel Formula:=IF(COUNTIF(A1#,0),dothis,dothat)
=LET(x, SEQUENCE(4,,1,1),
COUNTIF(x,0)
)