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
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 ElseIf
s
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] 삭제
몇 마디 만하겠습니다