按行创建文本框userform vba上的列

时间:2016-04-07 13:09:54

标签: excel vba excel-vba

是否有人可以指导我正确指导以下代码?我想在运行时按行&创建一个文本框。列。以下仅创建一行&不是多行。我希望列保持相同&只是不断增加行数。在此先感谢:)

    Dim txtB1 As Control
    Dim i
    For i = 0 To 4
    Set txtB1 = UserForm.Controls.Add("Forms.TextBox.1")
    With txtB1
        .Name = "chkDemo" & i
        .Height = 20
        .Width = 50
        .Left = 30 * i * 2
        .Top = 15
        .ControlTipText = "Type of Bug"
        End With
    Next i

1 个答案:

答案 0 :(得分:3)

每个维度都需要For循环(行列)。

Dim txtB1 As Control
Dim i, jrow

For jrow = 1 To 5
    For i = 0 To 4
        Set txtB1 = UserForm.Controls.Add("Forms.TextBox.1")
        With txtB1
        .Name = "chkDemo" & i
        .Height = 20
        .Width = 50
        .Left = 50 * i + 2
        .Top = 20 * jrow + 15
        .ControlTipText = "Type of Bug"
        End With
    Next i
Next jrow

结果:

enter image description here