Reputation: 15
I have to display YES or NO from the given data of EXCEL . I have tried to write program . But i cant find the solution . It displays YES only not NO even if output should be NO . Please Help me with this program .
I have to check the data of whole column of C ( data is from number 2 to 1439 of the column). If the data is >=0.003 , It should display NO else it should display Yes.
CODE:
' Declare array
Dim arrMarks(0 To 1437) As Double
Sub ArrayLoops()
' Fill the array with numbers
Dim i As Integer
For i = LBound(arrMarks) To UBound(arrMarks)
arrMarks(i) = Range("C2:C1439").Select
Next i
' Using If statement
For i = LBound(arrMarks) To UBound(arrMarks)
If arrMarks(i) >= 0.003 Then
MsgBox ("NO")
Else
End If
Next i
MsgBox ("YES")
End Sub
Upvotes: 0
Views: 123
Reputation: 14537
Your "YES" was outside of both the loop and the test, so that is why you get it every time! ;)
Look at the way to fill an array directly from a range with .Value
:
Sub ArrayLoops()
'Declare array
Dim arrMarks()
Dim i As Integer
'Fill the array with range
arrMarks = Range("C2:C1439").Value
'Using If statement
For i = LBound(arrMarks, 1) To UBound(arrMarks, 1)
If arrMarks(i, 1) >= 0.003 Then
MsgBox ("NO")
Else
MsgBox ("YES")
End If
Next i
End Sub
Upvotes: 1