UserForm para capturar datos de 15 TextBox

Buenas

Dentro del Userform agregue este código.

Private Sub CommandButton1_Click()

 Dim fila As Long

Dim duplicados As Boolean

 'Obtener la fila disponible

fila = Application.WorksheetFunction.CountA(Range("A:A")) + 1

duplicados = False

 'Validar si se han ingresado datos duplicados

For i = 1 To fila

    If Cells(i, 1).Value = UserForm1.TextBox1.Value Then

        If Cells(i, 2).Value = UserForm1.TextBox2.Value Then

            If Cells(i, 3).Value = UserForm1.TextBox3.Value Then

                'Se encontraron datos duplicados

                MsgBox "Datos duplicados en la fila " & i

                duplicados = True

            End If

        End If

    End If

Next i

If Not duplicados Then

    'Insertar datos capturados

    Cells(fila, 1).Value = UserForm1.TextBox1.Value

    Cells(fila, 2).Value = UserForm1.TextBox2.Value

    Cells(fila, 3).Value = UserForm1.TextBox3.Value

     'Limpiar cajas de texto

    UserForm1.TextBox1.Value = ""

    UserForm1.TextBox2.Value = ""

    UserForm1.TextBox3.Value = ""

     'Notificar al usuario

    MsgBox "Datos insertados en la fila " & fila

End If

 End Sub

Sin embargo quisiera saber como adaptarlo a 15 TextBox?

Lo intente con

Private Sub CommandButton1_Click()
Dim fila As Long
Dim duplicados As Boolean

'Obtener la fila disponible
fila = Application.WorksheetFunction.CountA(Range("A:B")) + 1
duplicados = False

'Validar si se han ingresado datos duplicados
For i = 1 To fila
If Cells(i, 1).Value = UserForm1.TextBox1.Value Then
If Cells(i, 2).Value = UserForm1.TextBox2.Value Then
If Cells(i, 3).Value = UserForm1.TextBox3.Value Then
If Cells(i, 4).Value = UserForm1.TextBox4.Value Then
If Cells(i, 5).Value = UserForm1.TextBox5.Value Then
If Cells(i, 6).Value = UserForm1.TextBox6.Value Then
If Cells(i, 7).Value = UserForm1.TextBox7.Value Then
If Cells(i, 8).Value = UserForm1.TextBox8.Value Then
If Cells(i, 9).Value = UserForm1.TextBox9.Value Then
If Cells(i, 10).Value = UserForm1.TextBox10.Value Then
If Cells(i, 11).Value = UserForm1.TextBox11.Value Then
If Cells(i, 12).Value = UserForm1.TextBox12.Value Then
If Cells(i, 13).Value = UserForm1.TextBox13.Value Then
If Cells(i, 14).Value = UserForm1.TextBox14.Value Then
If Cells(i, 15).Value = UserForm1.TextBox15.Value Then
'Se encontraron datos duplicados
MsgBox "Datos duplicados en la fila " & i
duplicados = True
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Next i

If Not duplicados Then
'Insertar datos capturados
Cells(fila, 1).Value = UserForm1.TextBox1.Value
Cells(fila, 2).Value = UserForm1.TextBox2.Value
Cells(fila, 3).Value = UserForm1.TextBox3.Value
Cells(fila, 4).Value = UserForm1.TextBox4.Value
Cells(fila, 5).Value = UserForm1.TextBox5.Value
Cells(fila, 6).Value = UserForm1.TextBox6.Value
Cells(fila, 7).Value = UserForm1.TextBox7.Value
Cells(fila, 8).Value = UserForm1.TextBox8.Value
Cells(fila, 9).Value = UserForm1.TextBox9.Value
Cells(fila, 10).Value = UserForm1.TextBox10.Value
Cells(fila, 11).Value = UserForm1.TextBox11.Value
Cells(fila, 12).Value = UserForm1.TextBox12.Value
Cells(fila, 13).Value = UserForm1.TextBox13.Value
Cells(fila, 14).Value = UserForm1.TextBox14.Value
Cells(fila, 15).Value = UserForm1.TextBox15.Value
'Limpiar cajas de texto
UserForm1.TextBox1.Value = ""
UserForm1.TextBox2.Value = ""
UserForm1.TextBox3.Value = ""
UserForm1.TextBox4.Value = ""
UserForm1.TextBox5.Value = ""
UserForm1.TextBox6.Value = ""
UserForm1.TextBox7.Value = ""
UserForm1.TextBox8.Value = ""
UserForm1.TextBox9.Value = ""
UserForm1.TextBox10.Value = ""
UserForm1.TextBox11.Value = ""
UserForm1.TextBox12.Value = ""
UserForm1.TextBox13.Value = ""
UserForm1.TextBox14.Value = ""
UserForm1.TextBox15.Value = ""
'Notificar al usuario
MsgBox "Datos insertados en la fila " & fila
End If

End Sub

Pero me da error en el Next

Añade tu respuesta

Haz clic para o