Creación de formulario en VB

Estoy creando un formulario y al ejecutarlo. Lleno los campos y al registrar, me aparece un error '1004' Error en el método Insert de la clase Range. Anexo los datos. De antemano muchas gracias por el apoyo. Saludos

Private Sub cmdRegistrar_Click()
ActiveSheet.Cells(2, 2).Select
Selection.EntireRow.Insert
ActiveSheet.Cells(2, 2) = txtFecha
ActiveSheet.Cells(2, 3) = txtID
ActiveSheet.Cells(2, 5) = txtFalla
ActiveSheet.Cells(2, 6) = txtAtiende
ActiveSheet.Cells(2, 8) = txtHora
ActiveSheet.Cells(2, 7) = txtReportador
ActiveSheet.Cells(2, 8) = txtArea
ActiveSheet.Cells(2, 9) = txtSolucion
ActiveSheet.Cells(2, 10) = txtNotas
txtFecha = Empty
txtID = Empty
txtFalla = Empty
txtAtiende = Empty
txtHora = Empty
txtReportador = Empty
txtArea = Empty
txtSolucion = Empty
txtNotas = Empty
txtFecha.SetFocus
End Sub

1 respuesta

Respuesta
1

He probado tu macro y no me da error. Pero comprueba en la columna 8 registra la hora y el área. De todos modos te adjunto otra que si quieres puedes cambiar. Solo tienes que corregir que los datos estén bien y cambiar donde pone "Hoja1" por la hoja donde quieres el ingreso de datos.

Private Sub cmdRegistrar_Click()
Set H1 = Sheets("Hoja1")
UF = H1.Range("B" & Rows.Count).End(xlUp).Row + 1
H1.Cells(UF, "B").Value = txtFecha.Value
H1.Cells(UF, "C").Value = txtID.Value
H1.Cells(UF, "D").Value = txtFalla.Value
H1.Cells(UF, "E").Value = txtAtiende.Value
H1.Cells(UF, "F").Value = txtReportador.Value
H1.Cells(UF, "G").Value = txtHora.Value
H1.Cells(UF, "H").Value = txtArea.Value
H1.Cells(UF, "I").Value = txtSolucion.Value
H1.Cells(UF, "J").Value = txtNotas.Value
txtFecha = Empty
txtID = Empty
txtFalla = Empty
txtAtiende = Empty
txtHora = Empty
txtReportador = Empty
txtArea = Empty
txtSolucion = Empty
txtNotas = Empty
txtFecha.SetFocus
End Sub

Salu2

Excelente amigo, muchas gracias por la información, funciono a la perfección. Abusando de tu amabilidad, como puedo agregar código para que mande un mensaje de advertencia si una casilla se queda en blanco. Anexo un ejemplo que tengo de otro trabajo.

If (Me.txtCodigo = Empty) Then
MsgBox "Debe ingresar un codigo de producto", vbExclamation, "ADVERTENCIA"
Me.txtCodigo.SetFocus
Set Producto1 = Nothing
Exit Sub

De antemano agradezco tu valioso apoyo

Saludos...

Prueba así a ver que tal.

Private Sub cmdRegistrar_Click()
'by Carlos Arrocha
For Each Ver In Me.Controls
caja = UCase(TypeName(Ver))
If caja = "TEXTBOX" Then
If Ver.Text = Empty Then
MsgBox ("Existe un campo vacio"), vbExclamation, "Información"
Ver.SetFocus
Exit Sub
Exit For
End If
'Else
End If
Next Ver
Set H1 = Sheets("Hoja1")
UF = H1.Range("B" & Rows.Count).End(xlUp).Row + 1
H1.Cells(UF, "B").Value = txtFecha.Value
H1.Cells(UF, "C").Value = txtID.Value
H1.Cells(UF, "D").Value = txtFalla.Value
H1.Cells(UF, "E").Value = txtAtiende.Value
H1.Cells(UF, "F").Value = txtReportador.Value
H1.Cells(UF, "G").Value = txtHora.Value
H1.Cells(UF, "H").Value = txtArea.Value
H1.Cells(UF, "I").Value = txtSolucion.Value
H1.Cells(UF, "J").Value = txtNotas.Value
txtFecha = Empty
txtID = Empty
txtFalla = Empty
txtAtiende = Empty
txtHora = Empty
txtReportador = Empty
txtArea = Empty
txtSolucion = Empty
txtNotas = Empty
txtFecha.SetFocus
End Sub

Salu2

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas