Error 1004 en el método Insert de clase rango

Solicito su amable apoyo con este tema:

Me aparece el error descrito en la pregunta de forma intermitente al ejecutar la macro al inicio no había tenido ningún tipo de problemas pero después de 600 líneas comenzó este error les comparto el código que utilizo

Private Sub CommandButton1_Click()

Sheets("Registro").Range("A2").Rows.Insert
Sheets("Registro").Range("A2").Value = Me.txt_fk.Value
Sheets("Registro").Range("C2").Value = Me.txt_fs.Value
Sheets("Registro").Range("D2").Value = Me.txt_fecha.Value
Sheets("Registro").Range("E2").Value = Me.ComboBox3.Value
Sheets("Registro").Range("I2").Value = Me.ComboBox1.Value
Sheets("Registro").Range("J2").Value = Me.ComboBox2.Value
Sheets("Registro").Range("K2").Value = Me.txt_dg.Value
Sheets("Registro").Range("M2").Value = Me.txt_cantidad.Value
Sheets("Registro").Range("N2").Value = Me.ComboBox4.Value
Sheets("Registro").Range("O2").Value = Me.txt_clave.Value
Sheets("Registro").Range("P2").Value = Me.txt_precio.Value
Sheets("Registro").Range("B2").Value = Me.bitacora.Value
Sheets("Registro").Range("H2").Value = Me.atencion1.Value
Sheets("Registro").Range("L2").Value = Me.txt_breve.Value
Sheets("Registro").Range("U2").Value = Me.solicitadox.Value

MsgBox "Captura exitosa"

Me.txt_fk.Value = ""
Me.txt_fs.Value = ""
Me.txt_fecha.Value = ""
Me.ComboBox3.Value = ""
Me.ComboBox1.Value = ""
Me.ComboBox2.Value = ""
Me.txt_dg.Value = ""
Me.txt_cantidad.Value = ""
Me.ComboBox4.Value = ""
Me.txt_clave.Value = ""
Me.txt_precio.Value = ""
Me.atencion1.Value = ""
Me.txt_breve.Value = ""
Me.solicitadox.Value = ""

Unload Me

datox.Show

End Sub

Respuesta
1

Sheets("Registro").Range("A2").Rows.Insert

¿Tienes celdas combinadas?

¿La hoja tiene autofiltro?

Mi recomendación es: no insertes una fila, eso hace más lento el proceso. Cada vez que insertes una fila, el proceso será más lento.

Lo ideal siempre es insertar el nuevo registro después del último dato.

Algo como esto. Ejemplo:

Private Sub CommandButton1_Click()
  Dim lr As Long
  '
  With Sheets("Registro")
    lr = .Range("A" & Rows.Count).End(3).Row + 1
    .Range("A" & lr).Value = Me.txt_fk.Value
    .Range("C" & lr).Value = Me.txt_fs.Value
    .Range("D" & lr).Value = Me.txt_fecha.Value
    .Range("E" & lr).Value = Me.ComboBox3.Value
    .Range("I" & lr).Value = Me.ComboBox1.Value
    .Range("J" & lr).Value = Me.ComboBox2.Value
    .Range("K" & lr).Value = Me.txt_dg.Value
    .Range("M" & lr).Value = Me.txt_cantidad.Value
    .Range("N" & lr).Value = Me.ComboBox4.Value
    .Range("O" & lr).Value = Me.txt_clave.Value
    .Range("P" & lr).Value = Me.txt_precio.Value
    .Range("B" & lr).Value = Me.bitacora.Value
    .Range("H" & lr).Value = Me.atencion1.Value
    .Range("L" & lr).Value = Me.txt_breve.Value
    .Range("U" & lr).Value = Me.solicitadox.Value
  End With
  MsgBox "Captura exitosa"
  '
  Me.txt_fk.Value = ""
  Me.txt_fs.Value = ""
  Me.txt_fecha.Value = ""
  Me.ComboBox3.Value = ""
  Me.ComboBox1.Value = ""
  Me.ComboBox2.Value = ""
  Me.txt_dg.Value = ""
  Me.txt_cantidad.Value = ""
  Me.ComboBox4.Value = ""
  Me.txt_clave.Value = ""
  Me.txt_precio.Value = ""
  Me.atencion1.Value = ""
  Me.txt_breve.Value = ""
  Me.solicitadox.Value = ""
  '
  Unload Me
  datox.Show
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas