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.
Thanks for any help I can get
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