Código que funciona pero necesito una variación (excel vba)

He tenido el proyecto un poco abandonado. Gracias a dante amor, empiezo a sacar mi proyecto poco a poco adelante.

Tengo un frm_articulos_buscar y el código de abajo me funciona perfecto. Pero me gustaría hacerle una variación.

Necesito que al pinchar en el botón modificar o botón eliminar, el txt_buscar y el listbox se queden en blanco.

Las líneas de código creo que sera:

txt_buscar.value = ""

listbox1.value = ""

pero no se donde ubicarlo. He probado pero solo se me vacia el textbox.

A ver si puede ayudarme.

Dim h1
Private Sub cmb_eliminar_Click()
    If txt_buscar.Value = "" Then
        MsgBox "Escribe un dato a buscar", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    If ListBox1.ListIndex = -1 Then
        MsgBox "Selecciona un artículo para eliminar", vkonly, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
            fila = ListBox1.List(ListBox1.ListIndex, 4)
    If (MsgBox("¿Seguro de querer eliminar el artículo seleccionado?", vbCritical + vbYesNo, " JJ VIDEOJUEGOS") = vbYes) Then
            h1.Rows(fila).Delete
        Else
            Cancel = 1
    End If
    'Call cmb_buscar_Click
End Sub
Private Sub cmb_volver_Click()
Unload Me
frm_articulos.Show
End Sub
'
Private Sub cmb_buscar_Click()
'Por.Dante Amor
    ListBox1.Clear
    If txt_buscar.Value = "" Then
        MsgBox "Escribe un dato a buscar", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    Set r = h1.Columns("B")
    Set b = r.Find(txt_buscar, LookAt:=xlPart)
    If Not b Is Nothing Then
        celda = b.Address
        Do
            'detalle
            ListBox1. AddItem h1. Cells(b.Row, "A")
            ListBox1. List(ListBox1.ListCount - 1, 1) = h1. Cells(b.Row, "B")
            ListBox1. List(ListBox1.ListCount - 1, 2) = h1. Cells(b.Row, "C")
            ListBox1. List(ListBox1.ListCount - 1, 3) = h1. Cells(b.Row, "D")
            ListBox1. List(ListBox1.ListCount - 1, 4) = h1. Cells(b.Row, "E")
            ListBox1.List(ListBox1.ListCount - 1, 4) = b.Row
            Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> celda
    End If
End Sub
Private Sub cmb_modificar_Click()
'Por.Dante Amor
    If ListBox1.ListIndex = -1 Then
        MsgBox "Selecciona un registro a modificar", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    Unload Me
    With frm_articulos_modificar
        .fila = ListBox1.List(ListBox1.ListIndex, 4)
        .Show
    End With
End Sub
'
Private Sub UserForm_Activate()
    Set h1 = Sheets("ARTICULOS")
End Sub

1 respuesta

Respuesta
2

Te anexo el código actualizado

Dim h1
'
Private Sub cmb_eliminar_Click()
    If txt_buscar.Value = "" Then
        MsgBox "Escribe un dato a buscar", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    If ListBox1.ListIndex = -1 Then
        MsgBox "Selecciona un artículo para eliminar", vkonly, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    fila = ListBox1.List(ListBox1.ListIndex, 4)
    If (MsgBox("¿Seguro de querer eliminar el artículo seleccionado?", vbCritical + vbYesNo, " JJ VIDEOJUEGOS") = vbYes) Then
        h1.Rows(fila).Delete
    Else
        Cancel = 1
    End If
    'Call cmb_buscar_Click
    '
    txt_buscar = ""
    ListBox1.Clear
End Sub
'
Private Sub cmb_volver_Click()
    Unload Me
    frm_articulos.Show
End Sub
'
Private Sub cmb_buscar_Click()
'Por.Dante Amor
    ListBox1.Clear
    If txt_buscar.Value = "" Then
        MsgBox "Escribe un dato a buscar", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    Set r = h1.Columns("B")
    Set b = r.Find(txt_buscar, LookAt:=xlPart)
    If Not b Is Nothing Then
        celda = b.Address
        Do
            'detalle
            ListBox1. AddItem h1. Cells(b.Row, "A")
            ListBox1. List(ListBox1.ListCount - 1, 1) = h1. Cells(b.Row, "B")
            ListBox1. List(ListBox1.ListCount - 1, 2) = h1. Cells(b.Row, "C")
            ListBox1. List(ListBox1.ListCount - 1, 3) = h1. Cells(b.Row, "D")
            ListBox1. List(ListBox1.ListCount - 1, 4) = h1. Cells(b.Row, "E")
            ListBox1.List(ListBox1.ListCount - 1, 4) = b.Row
            Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> celda
    End If
End Sub
'
Private Sub cmb_modificar_Click()
'Por.Dante Amor
    If ListBox1.ListIndex = -1 Then
        MsgBox "Selecciona un registro a modificar", vbInformation, "JJ VIDEOJUEGOS"
        Exit Sub
    End If
    Unload Me
    With frm_articulos_modificar
        .fila = ListBox1.List(ListBox1.ListIndex, 4)
        .Show
    End With
    '
    txt_buscar = ""
    ListBox1.Clear
End Sub
'
Private Sub UserForm_Activate()
    Set h1 = Sheets("ARTICULOS")
End Sub

.

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

.

Avísame cualquier duda

.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas