=INDEX(A1:G1,0,SUMPRODUCT(LARGE((A1:G1>0)*COLUMN(A1:G1),COUNTIF(A1:G1,">0"))))
簡問簡答
Function FirstNonZero(ByVal arr) As Integer
For nI = 0 To UBound(arr)
If arr(nI) > 0 Then
FirstNonZero = arr(nI)
Exit For
End If
Next nI
End Function
Sub Main()
nums = Array(0, 0, 3, 0, 16, 44, 23)
Debug.Print FirstNonZero(nums)
End Sub
改題目改答案
Function FirstNonZeroRange(ByVal rng) As Integer
For Each c In rng
If c > 0 Then
FirstNonZeroRange = c
Exit For
End If
Next
End Function
Sub Main()
rng = Range("A1:G1").Cells
Range("I1") = FirstNonZeroRange(rng)
Debug.Print Range("I1")
End Sub