nandesh kalyankar
nandesh kalyankar

Reputation: 302

create text box by row & column on a userform vba

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

Upvotes: 0

Views: 2221

Answers (1)

Ru Hasha
Ru Hasha

Reputation: 956

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

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:

enter image description here

Upvotes: 3

Related Questions