Compartir a través de

error 1004 en amarillo

Anónimas
2015-07-11T16:33:09+00:00

Private Sub CommandButton1_Click()

Dim file As Integer

For file = 2 To 1000

    If Hoja1.Cells(fila, 2) = "" Then

        Hoja1.Cells(fila, 2) = TextBox1.Text

        Hoja1.Cells(fila, 3) = TextBox2.Text

        Hoja1.Cells(fila, 4) = TextBox3.Text

        Hoja1.Cells(fila, 5) = TextBox4.Text

        Hoja1.Cells(fila, 6) = TextBox5.Text

        Hoja1.Cells(fila, 7) = TextBox6.Text

        Hoja1.Cells(fila, 8) = TextBox7.Text

        Hoja1.Cells(fila, 9) = TextBox8.Text

        MsgBox "su producto ha sido ingresado"

        TextBox2.Text = ""

        TextBox3.Text = ""

        TextBox4.Text = ""

        TextBox5.Text = ""

        TextBox6.Text = ""

        TextBox7.Text = ""

        TextBox8.Text = ""

        TextBox9.Text = ""

    Exit Sub

    End If

Next

End Sub

Private Sub UserForm_Click()

End Sub

Microsoft 365 y Office | Excel | Para la casa | Windows

Pregunta bloqueada. Esta pregunta se migró desde la Comunidad de Soporte técnico de Microsoft. Puede votar si es útil, pero no puede agregar comentarios o respuestas ni seguir la pregunta.

0 comentarios No hay comentarios

1 respuesta

Ordenar por: Muy útil
  1. Anónimas
    2015-07-11T21:12:33+00:00

    Hola Miguel.

    1.- Has puesto tu código, pero no has hecho ninguna pregunta.

    2.- Por el título parece que te provoca el error 1004  ¿En que linea?

    Debería ser otro tipo de error (salvo que no tengas "Option Explicit" en tu primera linea de código). Yo detecto dos errores en tu código:

    1.- Utilizas la variable fila pero declaras la variable file (el bucle itera con esta última), posiblemente esta es la causa del error 1004 (fila = 0).

    2.- Lees desde los cuadros de texto TextBox1 a TextBox8  y más tarde limpias los cuadros de texto TextBox2 a TextBox9. 

    Prueba así...

    Private Sub CommandButton1_Click()

      Dim fila As Integer

      For fila = 2 To 1000

        If Hoja1.Cells(fila, 2) = "" Then

          Hoja1.Cells(fila, 2) = TextBox1.Text

          Hoja1.Cells(fila, 3) = TextBox2.Text

          Hoja1.Cells(fila, 4) = TextBox3.Text

          Hoja1.Cells(fila, 5) = TextBox4.Text

          Hoja1.Cells(fila, 6) = TextBox5.Text

          Hoja1.Cells(fila, 7) = TextBox6.Text

          Hoja1.Cells(fila, 8) = TextBox7.Text

          Hoja1.Cells(fila, 9) = TextBox8.Text

          MsgBox "su producto ha sido ingresado"

          TextBox1.Text = ""

          TextBox2.Text = ""

          TextBox3.Text = ""

          TextBox4.Text = ""

          TextBox5.Text = ""

          TextBox6.Text = ""

          TextBox7.Text = ""

          TextBox8.Text = ""

          Exit Sub

        End If

      Next

    End Sub

    ... y si aún te falla, aporta más datos con los que poder intentar ayudarte.

    ¿Le ha resultado útil esta respuesta?

    0 comentarios No hay comentarios