在userform vba上按行和列创建文本框

时间:2022-11-19 21:48:04

Could any one direct me in right direction for the following code? I want to create a text box at run time by row & column.The following creates only a row & not multiple rows. I want the columns to remain same & just keep increasing rows. Thanks in advance :)

任何人都可以指导我正确的方向以获取以下代码吗?我想在运行时按行和列创建一个文本框。以下只创建一行而不是多行。我希望列保持相同并且只是保持增加的行。提前致谢 :)

    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 个解决方案

#1


3  

You need a For loop for each dimension (rows and columns).

每个维度(行和列)都需要一个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

Result:

在userform vba上按行和列创建文本框

#1


3  

You need a For loop for each dimension (rows and columns).

每个维度(行和列)都需要一个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

Result:

在userform vba上按行和列创建文本框