我正在处理一个userform,其中有几个radiobuttons和复选框。我想在我的工作表中分别在不同的单元格位置捕获它们。但是当我的代码只捕获复选框响应时,我的代码错误地捕获了radiobutton标题。
以下是我的代码:
Dim ctrl As Control
ReDim arr(4) As String
Dim arrstr As String
Dim i As Integer
i = 1
For Each ctrl In UserForm1.Controls
If TypeOf ctrl Is MSForms.CheckBox Then
If ctrl.Value = True Then
arr(i) = ctrl.Caption
i = i + 1
Else
End If
End If
Next ctrl
For i = 1 To 4
a = i - 1
If arr(a) = "" Then
temp = arr(a)
arr(a) = arr(a + 1)
arr(a + 1) = temp
a = a + 1
End If
Next i
Count = 0
For x = 0 To UBound(arr)
If arr(x) <> "" Then
Count = Count + 1
Else
Count = Count + 0
End If
Next x
MsgBox Count
ReDim Preserve arr(Count - 1)
arrstr = Join(arr, ",")
MsgBox arrstr
End Sub
答案 0 :(得分:0)
使用
If TypeName(ctrl) = "CheckBox" Then