I'm Working with a button command, but can't see what's wrong with this code using elseif statements

Alan

What this code is supposed to do is that if you have a number in cell 2,2 and it's between a range of those if statements, it will give you a number in cell 3,3. The problem is that it only works on the first 3 statements. The fourth one doesn't work. It gives you number 1 instead of number 2.

*note: the program uses more statements but this is just to show that the problem is after the third statement, and sorry for my English.

Cell 3,6= 5

Cell 3,7= 10

'MEC
If sheet1.Cells(2, 2) = Empty Then
            sheet3.Cells(3, 3) = ""
            sheet4.Cells(3, 3) = 0

'MEC limited
ElseIf sheet2.Cells(2, 2) = 1 Then
    sheet3.Cells(3, 3) = 0

'MEC aceptable
ElseIf sheet1.Cells(2, 2) > 1 < sheet.Cells(3, 6) Then
    sheet3.Cells(3, 3) = 1

'MEC Good
ElseIf sheet1.Cells(2, 2) > 5 <= sheet2.Cells(3, 7) Then
    sheet3.Cells(3, 3) = 2                 
End If

End Sub
peege

You had a typo in your sheets for 'MEC Aceptable. sheet.Cells. Judging by the context, it looks like it should be Sheet2.Cells

ElseIf sheet1.Cells(2, 2) > 1 < sheet.Cells(3, 6) Then

In addition to that, try using Select Case. You can use IF statements, but Select Case gets handy when you have many ElseIfs

Select Case (Sheet1.Cells(2, 2).Value)

    Case Is = ""
        Sheet3.Cells(3, 3) = ""
        Sheet4.Cells(3, 3) = 0
    Case Is = 1
        Sheet3.Cells(3, 3) = 0
    Case Is <= Sheet2.Cells(3, 6) 'There was typo in your orig code.. Sheet2?
        Sheet3.Cells(3, 3) = 1
    Case Is <= Sheet2.Cells(3, 7)
        Sheet3.Cells(3, 3) = 2

End Select

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

I'm using iron:router v1.0.7 but this.render() is "undefined". I can't see what I'm doing wrong

분류에서Dev

Copy-item failing without error, I'm sure it's something simple but I can't see it

분류에서Dev

How can I see which user is working on what task in Fogbugz?

분류에서Dev

Can I see what's going on in a tmux session without attaching to it?

분류에서Dev

What's wrong with this tar command?

분류에서Dev

using lappy and elseif command

분류에서Dev

Can I see the number of PCI slots with a command?

분류에서Dev

How can I tell what version of Linux I'm using?

분류에서Dev

Android code having error at the back-end. Yet I can't figure where the code goes wrong

분류에서Dev

What's wrong with this dictionary comprehension code?

분류에서Dev

What's wrong with my code here?

분류에서Dev

Can't see why I'm getting undefined method form_for

분류에서Dev

Can't access mat's data after using copyTo command

분류에서Dev

Can someone help me figure out what's wrong with my code?. It translates RNA sequences into proteins

분류에서Dev

Why can't I see gnome extensions?

분류에서Dev

I'm getting odd output from XOR. Can someone tell me what I'm doing wrong?

분류에서Dev

I'm getting odd output from XOR. Can someone tell me what I'm doing wrong?

분류에서Dev

Why is this code not working correctly? Won't take the elif statements

분류에서Dev

What's wrong with this SQL (Subquery using IN)?

분류에서Dev

What's wrong with using static for Parent Activities?

분류에서Dev

Can I see the summed up results of the ping command while it is running?

분류에서Dev

What's wrong with jquery document ready function working with jquery mobile?

분류에서Dev

For loop not working as expected, what am I doing wrong?

분류에서Dev

What is the wrong with this .bat excuting FFmpeg command using variables?

분류에서Dev

Can't find using yum search, but can see it in yum list

분류에서Dev

How can I ensure what I'm about to str_ireplace isn't a part of a url?

분류에서Dev

How can I get the source code of a command?

분류에서Dev

Can anyone help me to find what is wrong in below code?

분류에서Dev

See what file system mount is using with -t auto

Related 관련 기사

  1. 1

    I'm using iron:router v1.0.7 but this.render() is "undefined". I can't see what I'm doing wrong

  2. 2

    Copy-item failing without error, I'm sure it's something simple but I can't see it

  3. 3

    How can I see which user is working on what task in Fogbugz?

  4. 4

    Can I see what's going on in a tmux session without attaching to it?

  5. 5

    What's wrong with this tar command?

  6. 6

    using lappy and elseif command

  7. 7

    Can I see the number of PCI slots with a command?

  8. 8

    How can I tell what version of Linux I'm using?

  9. 9

    Android code having error at the back-end. Yet I can't figure where the code goes wrong

  10. 10

    What's wrong with this dictionary comprehension code?

  11. 11

    What's wrong with my code here?

  12. 12

    Can't see why I'm getting undefined method form_for

  13. 13

    Can't access mat's data after using copyTo command

  14. 14

    Can someone help me figure out what's wrong with my code?. It translates RNA sequences into proteins

  15. 15

    Why can't I see gnome extensions?

  16. 16

    I'm getting odd output from XOR. Can someone tell me what I'm doing wrong?

  17. 17

    I'm getting odd output from XOR. Can someone tell me what I'm doing wrong?

  18. 18

    Why is this code not working correctly? Won't take the elif statements

  19. 19

    What's wrong with this SQL (Subquery using IN)?

  20. 20

    What's wrong with using static for Parent Activities?

  21. 21

    Can I see the summed up results of the ping command while it is running?

  22. 22

    What's wrong with jquery document ready function working with jquery mobile?

  23. 23

    For loop not working as expected, what am I doing wrong?

  24. 24

    What is the wrong with this .bat excuting FFmpeg command using variables?

  25. 25

    Can't find using yum search, but can see it in yum list

  26. 26

    How can I ensure what I'm about to str_ireplace isn't a part of a url?

  27. 27

    How can I get the source code of a command?

  28. 28

    Can anyone help me to find what is wrong in below code?

  29. 29

    See what file system mount is using with -t auto

뜨겁다태그

보관