excel vba多个复选框

时间:2016-03-10 14:13:54

标签: excel-vba vba excel

我正在尝试收集用户表单中的许多复选框的状态,并为处于错误状态的复选框写入X或当处于True状态时为V, 但是当它到达该行时,我总是得到运行时错误:

For Each chk In UserForm1

运行时错误'438':对象不支持此属性或方法

这是我到目前为止所做的:

    Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim Col As Long
Dim chk As Control
Set ws = Worksheets("Sheet1")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
  .End(xlUp).Offset(1, 1).Row
Col = 1
MultiPage1.Value = 1
For Each chk In UserForm1
    If GroupName = Rooms Then
        If (chk.Value) = True Then
            ws.Cells(iRow, Col).Value = V
            Col = Col + 1
        End If
        Else
            ws.Cells(iRow, Col).Value = X
            Col = Col + 1
    End If
Next
End Sub

任何建议?

提前感谢任何帮助或潜在客户

1 个答案:

答案 0 :(得分:0)

在UserForm的控件上指定循环。

For Each chk In UserForm1.Controls