【问题标题】:command button click on Userform enter textbox to cell, then loop columns per click命令按钮单击用户窗体将文本框输入到单元格,然后每次单击循环列
【发布时间】:2016-04-03 11:06:56
【问题描述】:

我对 VBA 很陌生。我创建了一个用户表单,其中包含需要将文本框数据传输到一系列单元格的文本框。我需要它处理的范围是列,例如 C8:AG8,因此一旦输入并单击文本框中的数据将循环到下一列以重复该过程。我需要循环从列到列,而不是行到行。谢谢。

到目前为止,我有以下内容,这只会填充一次:

Private Sub CommandButton1_Click()
    Range("C8") = TextBox1.Value
    Range("C9") = TextBox2.Value
    Range("C10") = TextBox3.Value
    Range("C11") = TextBox4.Value
    Range("C12") = TextBox5.Value
    Range("C13") = TextBox6.Value
    Range("C14") = TextBox7.Value
    Range("C15") = TextBox8.Value
    Range("C16") = TextBox9.Value
    Range("C17") = TextBox10.Value
    Range("C18") = TextBox11.Value
    Range("C19") = TextBox12.Value
    Range("C20") = TextBox13.Value
    Range("C21") = TextBox14.Value
    Range("C22") = TextBox15.Value
    Range("C23") = TextBox16.Value
    Range("C24") = TextBox17.Value
    Range("C25") = TextBox18.Value
End Sub

【问题讨论】:

    标签: vba excel ranged-loops


    【解决方案1】:

    这样的事情可能会做到:

    Private Sub CommandButton1_Click()
    
    Dim i As Integer
    
    For i = 3 To 33 'Columns C to AG
    
        Cells(8, i) = TextBox1.Value
        Cells(9, i) = TextBox2.Value
        Cells(10, i) = TextBox3.Value
        Cells(11, i) = TextBox4.Value
        Cells(12, i) = TextBox5.Value
        Cells(13, i) = TextBox6.Value
        Cells(14, i) = TextBox7.Value
        Cells(15, i) = TextBox8.Value
        Cells(16, i) = TextBox9.Value
        Cells(17, i) = TextBox10.Value
        Cells(18, i) = TextBox11.Value
        Cells(19, i) = TextBox12.Value
        Cells(20, i) = TextBox13.Value
        Cells(21, i) = TextBox14.Value
        Cells(22, i) = TextBox15.Value
        Cells(23, i) = TextBox16.Value
        Cells(24, i) = TextBox17.Value
        Cells(25, i) = TextBox18.Value
    
    Next i
    
    End Sub
    

    【讨论】:

    • 您好,谢谢您,我还有一个问题。 (更大)首先我有
    猜你喜欢
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 2016-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多