设置用户窗体文本框的标记属性

时间:2018-11-14 21:03:14

标签: vba excel-2013

当表单激活时,我需要一些帮助来设置UserForm中TextBox的Tag属性,然后检查以确保带有df2 = pd.concat([f, s], axis=1) df2[1] = df2.groupby(0).transform(lambda s: s.expanding().mean()) pd.DataFrame(df2.values.reshape(-1,4), columns=df.columns) Visitor Home Visitor_rtg Home_rtg 0 Sixers 83.4 Celtics 100.7 1 Thunder 97.7 Warriors 105.6 2 Bucks 110.2 Hornets 109.2 3 Pelicans 88.1 Sixers 86.3 4 Hornets 99.65 Wizards 102.3 的Text Box与单击Save Button时的条件匹配。我认为问题在于用户窗体激活时如何设置标签属性,但是如果用户窗体激活时代码逻辑中有错误,我不会感到惊讶。预先感谢您的协助。

激活用户窗体的代码:

Tag

单击“保存”按钮时的代码:

Private Sub UserForm_Activate()
    Dim i As Long

        For Each ctrl In UWchecklist.Controls
            Select Case TypeName(ctrl)
                Case Is = "ComboBox"
                    If ctrl.Tag = "yesno" Then
                        ctrl.RowSource = "YesNo"
                    End If
                    ctrl.Font.Size = 10
                Case Is = "TextBox"
                    ctrl.Font.Size = 10
                        For i = 1 To 30
                            If ctrl.Name = ("uwtxTB" & i) Then
                                ctrl.Tag = "Check"
                            End If
                        Next i
            End Select
        Next ctrl
End Sub

1 个答案:

答案 0 :(得分:0)

我知道了;问题不在UserForm Activate中。它在保存并继续代码中。我认为我没有研究足够的If条件,因此我设置了Select Case,现在可以使用了。这可能不是最优雅的解决方案。

For Each ctrl In UWchecklist.Controls
    If ctrl.Tag = "Check" Then
        Select Case ctrl.Value
            Case Is = ""
                ctrl.BackColor = vbWhite
            Case Is = "X"
                ctrl.BackColor = vbWhite
                ctrl.Text = "X"
            Case Is = "NA"
                ctrl.BackColor = vbWhite
                ctrl.Text = "NA"
            Case Is <> "X"
                ctrl.Value = vbNullString
                ctrl.BackColor = vbRed
            Case Is <> "NA"
                ctrl.Value = vbNullString
                ctrl.BackColor = vbRed
        End Select
    End If
Next ctrl

MsgBox "Only a value of " & "X " & "or " & "NA " & "is allowed.", 0, "DATA ENTRY ERROR"