我想控制两个下拉列表来告诉自动运行哪个宏

问题描述 投票:0回答:1

目前我有这个代码

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = True ' <-- just for tests
If Not Intersect(Target, Range("C1")) Is Nothing Then
  Select Case Target.Value  
   Case "Expander 1 eff"     
      CopyIncreaseRecord      
      Case "Expander 2 eff"  
     CopyIncreaseRecord       
      Case "Pump eff"  
       CopyIncreaseRecord     
      Case "Net Power"  
      CopyIncreaseRecordNetPower      
   End Select 
End If

End Sub

在Sheet5(Graph1)查看代码下。

目前,我正在使用单元格 C1 中的一个下拉菜单来告诉当我在单元格 C1 中选择一个选项时要自动运行哪个宏,

现在我想在单元格 C1 和单元格 C2 中有两个下拉菜单, 例如,如果选择 C1“Expander 2 eff”并且选择 C2“Cycle eff”,我希望宏 Expander2effvsCycleeff 运行 如果选择 C1“Expander 2 eff”并且选择 C2“Massflowrate”,我希望运行宏 Expander2effvsMassflowrate。

请帮忙,提前谢谢

我尝试了人工智能,但它没有给我在两个单元格中进行选择

excel vba
1个回答
0
投票

工作表更改:调用依赖于下拉菜单的过程

Private Sub Worksheet_Change(ByVal Target As Range)

    If Intersect(Me.Range("C1,C2"), Target) Is Nothing Then Exit Sub
    
    Dim Str1 As Range: Str1 = LCase(CStr(Me.Range("C1")))
    Dim Str2 As Range: Str2 = LCase(CStr(Me.Range("C2")))

    ' This may not be necessary if non of the procedures write to this sheet!
    Application.EnableEvents = False

    Select Case Str1
        Case "expander 1 eff"
            CopyIncreaseRecord
        Case "expander 2 eff"
            Select Case Str2
                Case "cycle eff": Expander2effvsCycleeff
                Case "massflowrate": Expander2effvsMassflowrate
                Case Else: ' CopyIncreaseRecord ' ???
            End Select
        Case "pump eff": CopyIncreaseRecord
        Case "net power": CopyIncreaseRecordNetPower
        Case Else: ' do nothing ???
    End Select

    ' This may not be necessary if non of the procedures write to this sheet!
    Application.EnableEvents = True

End Sub
© www.soinside.com 2019 - 2024. All rights reserved.