【问题标题】:Nested if but Operators not picking up values嵌套 if 但运算符不获取值
【发布时间】:2017-09-07 11:40:45
【问题描述】:
Private Sub Check()

  For rwIndex = 2 To 227
    If (Len(Cells(rwIndex, 1).Value) > 0) Then
      If (Cells(rwIndex, 3).Value < 6000) Then
        Cells(rwIndex, 6).Value = " Below 6M Is Not Acceptable"
      ElseIf (Cells(rwIndex, 3).Value > 6000) And  (Cells(rwIndex,3).Value < 8000) Then
        Cells(rwIndex, 6).Value = " Not As Per Strategy"
      End If
      If Len(Cells(rwIndex, 5).Value) > 0 Then
        If (Cells(rwIndex, 5).Value < 0) Then
          Cells(rwIndex, 6).Value = Cells(rwIndex, 6).Value & "  Negative Growth Is Inacceptable"
        Else:
          If Cells(rwIndex, 5).Value < 15 Then
            Cells(rwIndex, 6).Value = Cells(rwIndex, 6).Value & "  Growth percent is Inappropriate"
          Else:
            If Cells(rwIndex, 5).Value < 25 Then
              Cells(rwIndex, 6).Value = Cells(rwIndex, 6).Value & "  Growth Percent is OK"
            Else:
              Cells(rwIndex, 6).Value = Cells(rwIndex, 6).Value & "  Growth percent Must be reviewed"
            End If
          End If
        End If
      End If
    End If
  Next rwIndex
End Sub

试试这个

但它停止比较 尝试了很多方法来使这段代码工作 尝试了 ELSEIF else 并嵌套 if too ...但值只是停止匹配

【问题讨论】:

    标签: excel if-statement nested numeric vba


    【解决方案1】:

    您正在测试 0.24(即 24%)等数字与 15 等数字。您可能打算将它们与 0.15(即 15%)和 0.25(即 25%)等数字进行比较。

    Private Sub Check()
    
      For rwIndex = 2 To 227
        If Len(Cells(rwIndex, 1).Value) > 0 Then
          If Cells(rwIndex, 3).Value < 6000 Then
            Cells(rwIndex, 6).Value = " Below 6M Is Not Acceptable"
          ElseIf Cells(rwIndex, 3).Value > 6000 And Cells(rwIndex,3).Value < 8000 Then
            Cells(rwIndex, 6).Value = " Not As Per Strategy"
          End If
          If Len(Cells(rwIndex, 5).Value) > 0 Then
            If Cells(rwIndex, 5).Value < 0 Then
              Cells(rwIndex, 6).Value = Cells(rwIndex, 6).Value & "  Negative Growth Is Inacceptable"
            ElseIf Cells(rwIndex, 5).Value < .15 Then
              Cells(rwIndex, 6).Value = Cells(rwIndex, 6).Value & "  Growth percent is Inappropriate"
            ElseIf Cells(rwIndex, 5).Value < .25 Then
              Cells(rwIndex, 6).Value = Cells(rwIndex, 6).Value & "  Growth Percent is OK"
            Else
              Cells(rwIndex, 6).Value = Cells(rwIndex, 6).Value & "  Growth percent Must be reviewed"
            End If
          End If
        End If
      Next rwIndex
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2014-10-17
      • 1970-01-01
      • 2017-01-03
      • 2012-02-03
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 2019-04-26
      • 2011-10-29
      相关资源
      最近更新 更多