VBA For user with userform textbox

时间:2018-05-09 18:08:41

标签: excel-vba vba excel

我使用userform输入数据并使用以下代码将数据转移到excel:

    Cells(1,1).Value = Textbox1.Value
    Cells(1,2).Value = Textbox2.Value
    Cells(1,3).Value = Textbox3.Value
......
    Cells(1,57).Value = Textbox57.Value
    Cells(1,58).Value = Textbox58.Value
    Cells(1,59).Value = Textbox59.Value

我将简化以下内容

Dim i As integer

For i = 1 to 59
Cells(1,i).Value = "Textbox" & i.Value
Next

但是“文本框”& i.Value部分

请建议,谢谢

1 个答案:

答案 0 :(得分:0)

这应该有效,

Dim i As Long

For i = 1 to 59
Cells(1,i).Value = Me.Controls("TextBox" & i).Value
Next