0

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
3
  • is using the msgbox sufficient enough for you? Commented Nov 19, 2015 at 9:56
  • Do you want to only display "No" once? Commented Nov 19, 2015 at 9:57
  • 2
    Isn't this something that would better left to an [excel-formula] or [conditional formatting]? Commented Nov 19, 2015 at 9:59

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

11 Comments

Thank you very much. But when i run the same code as yours it there was 'Run time Error 13': Type Mismatch. I dont know what it is and how to get rid of it . Can you please help me !
When you have an error, plz also specify on which line! ;) My guess is that it is on the arrMarks = ... line, try the edit! ;)
It should be highlighted in yellow! ;)
If you have a type mismatch, it would suggest that the data has a different type in a cell. Depends on your error handling and whats calling the code when debugging. Try in the VBIDE selecting Tools:Options:General: Break On All Errors. That should stop exactly at the error. Don't forget to switch it back it its original setting though!
to know wiwh line errors hit DEBUG when it errors, not END.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.