在特定工作表上输入数据时将两个案例放在一起

时间:2016-07-26 16:50:09

标签: excel vba excel-vba

我在项目管理的可视日历上工作了一段时间。日历采用用户形式: UserForm http://i68.tinypic.com/263bwuh.png

我目前有一个代码集,根据他们为“影响”选择的值,将数据过滤到相应的工作表 - “高”或“低”

按“输入项目”

Private Sub enterButton_Click()

    If Not CheckInputs Then Exit Sub 'check for fields to have values
    Process GetWs(Me.impactCombobox.Value) ' process data passing the proper worksheet got from GetWs() function
    MsgBox "Project Entered Successfully"
    ClearUFData 'clear the data

GetWS功能:

Function GetWs(impact As String) As Worksheet
    Select Case impact
        Case "High"
            Set GetWs = Worksheets("HI Project Work Database")
        Case "Low"
            Set GetWs = Worksheets("LI Project Work Database")
'        Case Else
    End Select
End Function

如何嵌入另一个特定于“项目工作”和“实施”选项按钮的案例中?

例如:

高影响力 - 项目工作=电子表格“HI项目工作数据库”

低影响力 - 项目工作=电子表格“LI项目工作数据库”

高影响力 - 实施=电子表格“HI实施数据库”

低影响力 - 实施=电子表格“LI实施数据库”

2 个答案:

答案 0 :(得分:0)

我认为你正在寻找这样的东西。

Function GetWs(impact As String) As Worksheet
    Select Case impact
        Case "High"
            Select Case True
                Case ProjectWorkOption.Value = True
                    Set GetWs = Worksheets("HI Project Work Database")
                Case ImplementationOption.Value = True
                    Set GetWs = Worksheets("HI Implementation Database")
            End Select
        Case "Low"
            Select Case True
                Case ProjectWorkOption.Value = True
                    Set GetWs = Worksheets("LI Project Work Database")
                Case ImplementationOption.Value = True
                    Set GetWs = Worksheets("LI Implementation Database")
            End Select
    End Select
End Function

显然你需要换掉选项按钮的名称。

答案 1 :(得分:0)

If添加Select Case。 假设您的User_Form名称为 User_Form1 。以下代码适合您:

Function GetWs(impact As String) As Worksheet
    Select Case impact
        Case "High"
            If UserForm1.Project_Work.Value = True Then
                Set GetWs = Worksheets("HI Project Work Database")
            Else
                If UserForm1.Implementation.Value = True Then
                    Set GetWs = Worksheets("HI Implementation Database")
                End If

            End If
        Case "Low"
            If UserForm1.Project_Work.Value = True Then
                Set GetWs = Worksheets("LI Project Work Database")
            Else
                If UserForm1.Implementation.Value = True Then
                    Set GetWs = Worksheets("LI Implementation Database")
                End If
            End If

'        Case Else

    End Select
End Function