我有几个工作表。有 3 个基于工作表名称的子程序 CALL 选项。我已经尝试重新排列和 If、If Not、Else 和 ElseIf、Exit Sub、End If 等。如果 CALL 完成并返回,它不可避免地会到达最后一个 CALL(这里... IsolOther)并执行它甚至通过前一个调用有效。我还试图找出 SELECT CASE 函数用于多种选择。 CBI、Fire、LEA 和 InCase 的 CALL 可以完美运行。问题是当我有一个不同名称的工作表时......我希望 CALL 转到 IsolOther。
Sub DetermineTabs()
'DETERMINE WHICH SUBROUTINE TO CALL BASED ON SHEET (TAB) NAME
Dim newTab As String
newTab = ActiveSheet.Name
'Call appropriate Category processing routine
'Call IsolNamesOnly Subroutine if ActiveSheet is named ... CBI
If newTab = "CBI" Then Call IsolNamesOnly Else
'Call IsolNamesOnly Subroutine if ActiveSheet is named ... Fire
If newTab = "Fire" Then Call IsolNamesOnly Else
'Call IsolNamesOnly Subroutine if ActiveSheet is named ... LEA
If newTab = "LEA" Then Call IsolNamesOnly Else
'Call IsolInCase Subroutine if ActiveSheet is named ... InCase
If newTab = "InCase" Then Call IsolInCase Else
'Call IsolOther Subroutine if ActiveSheet is named ... anything else
If newTab <> "CBI" Or newTab <> "Fire" Or newTab <> "LEA" Or newTab <> "InCase" Then Call IsolOther Else
End Sub
我还尝试过“If Not newTab = "CBI"Or newTab = "Fire"Or newTab = "LEA"Or newTab = "InCase"Then Call IsolOther Else"(不带引号作为最后一个 IF 行的替代),以及将最后一行设为单独的 If Not/Else,但我失败了。如果前 4 张都没有找到,我想执行那个 CALL 和 End Sub。我查看了问题 60781118、51274411、24684092 和其他 Google 查询。帮助 。 . .请。
最佳答案
考虑SELECT...CASE
并将多个条件与 Case Else
健康)状况。
Select Case newTab
Case "CBI", "LEA", "Fire"
Call IsolNamesOnly
Case "InCase"
Call IsolInCase
Case Else
Call IsolOther
End Select
关于excel - 多个 If/Then 调用选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70400476/