Forum Discussion

Excel's avatar
Excel
Iron Contributor
Aug 10, 2022

Query related to Userform

Hello Everyone, 

 

I have written VBA code in Append Text to Row Button :

 

 

I want the vba code in the user form to be able to loop through a selected range (A4:A14) ,in which the code starts from row A4 but i dont know how to make the code more dynamic so that once someone types text in the textbox and appends the text to the new rows , its offsets to the row underneath it.

 

Please help. 

 

Here is a attached file.

1 Reply

  • Excel 

    I made the text box multi-line and set it to create a new line when you press Enter.

     

    Private Sub CommandButton1_Click()
        Dim i As Variant
        Dim rowcounter As Long
        rowcounter = Cells(Rows.Count, 1).End(xlUp).Row
        For Each i In Split(Me.TextBox1, vbCrLf)
            rowcounter = rowcounter + 1
            Cells(rowcounter, 1).Value = i
        Next i
        Me.TextBox1 = ""
    End Sub

     

Resources