下面的代码根据哪些单元格包含"是"来增加变量。它一直工作直到我使用自动填充来设置F13中的任何单元格的值:F59到"是"。当我输入单词"是"手动,不会发生运行时错误。但是自动填充,似乎导致了这个问题。
Select Case (changedcell)
'Issues Mgmt
Case Range("F15"), Range("F19"), Range("F23"), Range("F27"), Range("F30"), Range("F39"), Range("F42"), Range("F45"), Range("F50"), Range("F53"), Range("F54") 'Issues
If Range("F15").Value = "Yes" Then
issues = issues + 1
End If
If Range("F19").Value = "Yes" Then
issues = issues + 1
End If
If Range("F23").Value = "Yes" Then
issues = issues + 1
End If
If Range("F27").Value = "Yes" Then
issues = issues + 1
End If
If Range("F30").Value = "Yes" Then
issues = issues + 1
End If
If Range("F39").Value = "Yes" Then
issues = issues + 1
End If
If Range("F42").Value = "Yes" Then
issues = issues + 1
End If
If Range("F45").Value = "Yes" Then
issues = issues + 1
End If
If Range("F50").Value = "Yes" Then
issues = issues + 1
End If
If Range("F53").Value = "Yes" Then
issues = issues + 1
End If
If Range("F54").Value = "Yes" Then
issues = issues + 1
End If
If issues > 1 Then
Application.EnableEvents = False
MsgBox "Issues Management has already been selected under another old solution category.", vbCritical, "Duplicate Use Case Selected"
Range(target.Address).Value = ""
End If
End Select
代码的第一部分是发生错误的地方。有什么想法吗?
Case Range("F15"), Range("F19"), Range("F23"), Range("F27"), Range("F30"), Range("F39"), Range("F42"), Range("F45"), Range("F50"), Range("F53"), Range("F54") 'Issues
答案 0 :(得分:1)
试试这个:
Dim rIssues As Range
Dim rCll As Range
Set rIssues = Range("F15,F19,F23,F27,F30,F39,F42,F45,F50,F53,F54")
For Each rCll In rIssues
If rCll.Value = "Yes" Then Issues = 1 + Issues
Next
If Issues > 1 Then
Application.EnableEvents = False
MsgBox "Issues Management has already been selected under another old solution category.", _
vbCritical, "Duplicate Use Case Selected"
Range(Target.Address).Value = ""
End If
建议阅读以下页面: