Macro de Botón eliminar manda error
Para: Dante Amor
Ante todo un cordial saludo, mi pregunta es la siguiente tengo una macro que elimina los registros tanto del listbox como de la hoja, cuando yo guardo un nuevo registro con mi formulario esta guarda y el listbox se actualiza automáticamente, pero el problema esta que si yo quiero borrar un registro al seleccionar del listbox esta no elimina, tengo que cerrar el formulario y abrir pero al seleccionar y eliminar el registro esta me manda un error hasta el punto que lo cierra por completo la hoja, indicando que excel dejo de funcionar.
Como puedo solucionar ese problema ya que tengo que cerrar forzosamente mi archivo y nuevamente iniciar.


La macro del botón ELIMINAR es la siguiente:
Private Sub Eliminar_Click()
'Act.Por.Dante Amor
Set h1 = Sheets("INGRESOS")
If ListBox1.ListIndex = -1 Then
MsgBox "Selecciona un registro del listbox"
Exit Sub
End If
'
Pregunta = MsgBox("Está seguro de eliminar el registro?", vbYesNo + vbQuestion, "ERROR")
If Pregunta = vbYes Then
Fila = Me.ListBox1.ListIndex + 2
h1.Rows(Fila).Delete
End If
End SubLa macro del botón GUARDAR es la siguiente:
Private Sub CommandButton3_Click()
Set h1 = Sheets("INGRESOS")
If ComboBox1 = "" Or ComboBox2 = "" Then
MsgBox "No son Datos suficientes para Guardar", vbInformation, ""
ComboBox1.SetFocus
Else
u = h1.Range("A" & Rows.Count).End(xlUp).Row + 1
If u < 2 Then u = 2
h1.Cells(u, 1) = TextBox1
h1.Cells(u, 2) = ComboBox1
h1.Cells(u, 3) = Date
h1.Cells(u, 4) = Format(Now, "hh:mm AM/PM")
h1.Cells(u, 5) = TextBox3
h1.Cells(u, 6) = TextBox4
h1.Cells(u, 7) = TextBox2
h1.Cells(u, 8) = ComboBox2
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox4 = Empty
ComboBox2 = Empty
ComboBox1 = Empty
MsgBox "Datos Guardados"
ComboBox1.SetFocus
End If
End Sub
1 respuesta
Respuesta de Dante Amor
2