简体   繁体   中英

I'm having trouble adding to this code

If vOverfly(arrayIndex, 10) <= 0 And vOverfly(arrayIndex, 7) = "CCYN" And Trim(vOverfly(arrayIndex, 3)) <> "--" Then
        resultCounter = resultCounter + 1

What do I need to do to add additional data to this line of code. Currently this line copies data where a number is <= 0 and is identified by CCYN. I am needing to know if other parameters fall below 0 such as "EOTN", "EOTH" and "CCYV". When I try to add these parameters it just ends up copying everything regardless of the number. Thanks.

you need to use brackets around your OR test for CCYN, EOTN,EOTH etc.

Sub Test()
    If vOverfly(arrayIndex, 10) <= 0 And (vOverfly(arrayIndex, 7) = "CCYN" Or vOverfly(arrayIndex, 7) = "EOTN") And Trim(vOverfly(arrayIndex, 3)) <> "--" Then
        resultCounter = resultCounter + 1


End Sub
 And vOverfly(arrayIndex, 7) = "CCYN" 

Try replacing the above part of code with this:

And IsNumeric (Application.match(vOverfly(arrayIndex, 7), _
  Array("CCYN", "EOTN", "EOTH", "CCYV"), 0))

If this code is inside a loop, you can make it faster by defining the array of values to match only once:

Dim arValues
arValues = Array("CCYN", "EOTN", "EOTH", "CCYV")

...

If vOverfly(arrayIndex, 10) <= 0 And _
  IsNumeric (Application.match(vOverfly(arrayIndex, 7), arValues, 0)) _ 
  And Trim(vOverfly(arrayIndex, 3)) <> "--" Then
    resultCounter = resultCounter + 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM