Usar Commandbuton Intregado un Listbox

Aquí dejo una imagen con lo que necesito, si no queda claro favor hacérmelo saber

2 Respuestas

Respuesta
1

Esta sería la macro para el botón INGRESAR:

Private Sub CommandButton1_Click()
'x Elsamatilde
'ingresar cantidad en textbox
dato = ListBox1.List(ListBox1.ListIndex)
Set busca = Sheets("INVENTARIO_EPP").Range("B:B").Find(dato, LookIn:=xlValues, lookat:=xlWhole)
If Not busca Is Nothing Then
    TextBox1 = Sheets("INVENTARIO_EPP").Range("C" & busca.Row)  'cantidad
    TextBox2 = Sheets("INVENTARIO_EPP").Range("D" & busca.Row)  'fecha
Else
    TextBox1 = "": TextBox2 = ""
End If
End Sub

Debes ajustar los nombres de tus controles. Observa que también te estoy devolviendo la fecha (para evitar consulta posterior ;) ... si no la necesitas eliminá esa instrucción.

Ahora, salvo que tengas algún otro evento en el 'DobleClick' del Listbox, esta tarea también la podés resolver en ese evento sin necesidad del botón.

'x Elsamatilde
'ingresar cantidad en textbox
dato = ListBox1.List(ListBox1.ListIndex)
Set busca = Sheets("INVENTARIO_EPP").Range("B:B").Find(dato, LookIn:=xlValues, lookat:=xlWhole)
If Not busca Is Nothing Then
    TextBox1 = Sheets("INVENTARIO_EPP").Range("C" & busca.Row)  'cantidad
    TextBox2 = Sheets("INVENTARIO_EPP").Range("D" & busca.Row)  'fecha
Else
    TextBox1 = "": TextBox2 = ""
End If

Si estas macros resuelven tu consulta no olvides valorar la respuesta.

A la 2da macro le faltó el encabezado, sería así:

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'x Elsamatilde
'ingresar cantidad en textbox
dato = ListBox1.List(ListBox1.ListIndex)
Set busca = Sheets("INVENTARIO_EPP").Range("B:B").Find(dato, LookIn:=xlValues, lookat:=xlWhole)
If Not busca Is Nothing Then
    TextBox1 = Sheets("INVENTARIO_EPP").Range("C" & busca.Row)  'cantidad
    TextBox2 = Sheets("INVENTARIO_EPP").Range("D" & busca.Row)  'fecha
Else
    TextBox1 = "": TextBox2 = ""
End If
End Sub

Sdos!

Viendo la respuesta del usuario Adriel me preguntaba si necesitas volcar a la hoja el valor del textbox o al textbox el valor de la hoja tal como interpreté tu consulta.

Creo que Adriel lo comprendió correctamente.

Dejo la aclaración por si en algún momento alguien necesita el paso al revés.

Sdos!

Respuesta
1

H o l a 

Te facilito la macro 

Private Sub CmdIngresar_Click()
Set h3 = Sheets("INVENTARIO_EPP ")
    nombre = ListBox1.List(ListBox1.ListIndex)
    Set r = h3.Columns("B")
    Set b = r.Find(nombre, lookat:=xlWhole)
    If Not b Is Nothing Then
            h3.Cells(b.Row, "C") = Val(TextBox8)
            h3.Cells(b.Row, "D") = TextBox9
           MsgBox "Actualizado"
           TextBox8.Text = ""
           TextBox9.Text = ""
    End If
End Sub
Private Sub ListBox1_Click()
Set h2 = Sheets("INVENTARIO_EPP ")
nombre = ListBox1.List(ListBox1.ListIndex)
Set r = h2.Columns("B")
Set b = r.Find(nombre, lookat:=xlWhole)
    If Not b Is Nothing Then
        ncell = b.Address
        Do
        TextBox8.Text = h2.Cells(b.Row, "C")
        TextBox9.Text = h2.Cells(b.Row, "D")
        Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> ncell
    End If
End Sub

Me comentas y valora para finalizar saludos!

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas