如何将字符串连接为整数,以用作for循环中的对象?

时间:2018-07-13 18:27:27

标签: excel excel-vba

目前我有12条这样的行,带有12个选项按钮:

If OptionButton1.Value = True Then
Cells(emptyRow, colnum).Value = 1
End If

我想替换为

For i = 1 To 3 '1 question
If OptionButton1.Value = True Then
Cells(emptyRow, colnum).Value = 1
End If
Next i

我该如何正确编写:“ OptionButton”&i.Value,以使i为数字,而OptionButton始终相同?

尝试了注释中的解决方案,将我的代码变成了这个,我遇到了编译错误。 labelstrr突出显示为错误。

Dim i As Integer
Dim j As Integer
Dim labelstrr As String
Dim labelnum As Integer

For j = 1 To 4 'columns 1 to 4
    For i = 1 To 3 '1 optionbutton
        labelstrr = "OptionButton" & labelnum
        If labelstrr.Value = True Then
        Cells(emptyRow, j).Value = i
        labelnum = labelnum + 1
        End If
    Next i
Next j

0 个答案:

没有答案