User Form Textbox looping

sjtjr73

New Member
Joined
May 1, 2020
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
Guys
I am having trouble looping through my textboxes on a user form. What is happening it either only add the last 4 text boxes to the spread sheet or add the first 4 skips 8 and adds last four also for some reason it deletes the the text from where the user form gets the data from.Code is below.
VBA Code:
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim sheet As String
Dim i As Integer
'Select the worksheet
Set ws = Worksheets("Crown")

'starts loop
For i = 1 To 30
  Controls("TextBox" & i).Value = ""

 
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

'copy the data to the database
ws.Cells(iRow, 3).Value = Date
ws.Cells(iRow, 4).Value = Me.Textbox1.Text
ws.Cells(iRow, 5).Value = Me.TextBox2.Text
ws.Cells(iRow, 6).Value = Me.TextBox3.Text
ws.Cells(iRow, 7).Value = Me.TextBox4.Text
ws.Cells(iRow, 4).Value = Me.TextBox5.Text
ws.Cells(iRow, 5).Value = Me.TextBox6.Text
ws.Cells(iRow, 6).Value = Me.TextBox7.Text
ws.Cells(iRow, 7).Value = Me.TextBox8.Text
ws.Cells(iRow, 4).Value = Me.TextBox9.Text
ws.Cells(iRow, 5).Value = Me.TextBox10.Text
ws.Cells(iRow, 6).Value = Me.TextBox11.Text
ws.Cells(iRow, 7).Value = Me.TextBox12.Text
ws.Cells(iRow, 4).Value = Me.TextBox13.Text
ws.Cells(iRow, 5).Value = Me.TextBox14.Text
ws.Cells(iRow, 6).Value = Me.TextBox15.Text
ws.Cells(iRow, 7).Value = Me.TextBox16.Text
ws.Cells(iRow, 4).Value = Me.TextBox17.Text
ws.Cells(iRow, 5).Value = Me.TextBox18.Text
ws.Cells(iRow, 6).Value = Me.TextBox19.Text
ws.Cells(iRow, 7).Value = Me.TextBox20.Text
ws.Cells(iRow, 4).Value = Me.TextBox21.Text
ws.Cells(iRow, 5).Value = Me.TextBox22.Text
ws.Cells(iRow, 6).Value = Me.TextBox23.Text
ws.Cells(iRow, 7).Value = Me.TextBox24.Text

'Ends loop
  Next i
  
  


End Sub
Thanks for any help I can get
 
I no longer understand what you are using, a userform or cells.
Your explanation is not clear.
I suggest you start over, explaining if you are using a userform and what layout you are using.
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Also I got the list box to populate and it send to my spread sheet. But the .clear is not working and the does not exit the loop after r
 
Upvote 0
OK I am using a user form to basically to pass data. Everything is working using the list box perfectly except for the .next it will hang up on it. Also it adds 3 blank rows of data at the end
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top