Registrar información desde ListBox
Visual Basic para Aplicaciones
3.002 visualizaciones desde el 11 de Agosto del 2017
Breve ejemplo de como pasar la información desde un Listbox a una hoja Excel con VBA (Visual Basic for Applications) en Excel.
Option Explicit
Private I As Single
Private A As Single
'Creado por David Garcia
'Contacto djgagarcia@gmail.com
Private Sub CommandButton1_Click()
A = ListBox1.ListCount
For I = 0 To ListBox1.ListCount - 1
If TextBox1.Text = ListBox1.List(I, 0) Then
MsgBox "EL ITEM SE ENCUENTRA EN LA LISTA.", vbCritical, "ERROR"
Exit Sub
End If
Next I
ListBox1.AddItem
ListBox1.List(A, 0) = TextBox1
ListBox1.List(A, 1) = TextBox2
ListBox1.List(A, 2) = TextBox3
Limpiar
MsgBox ListBox1.ListCount
End Sub
Sub Limpiar()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
ListBox1.ListIndex = -1
TextBox1.SetFocus
End Sub
Private Sub CommandButton2_Click()
If ListBox1.ListIndex = -1 Then: Exit Sub
ListBox1.List(ListBox1.ListIndex, 2) = TextBox3
Limpiar
End Sub
Private Sub CommandButton3_Click()
If ListBox1.ListIndex = -1 Then: Exit Sub
ListBox1.RemoveItem ListBox1.ListIndex
Limpiar
End Sub
Private Sub CommandButton4_Click()
Dim I As Integer
Dim Uf As Long
With Hoja1
Uf = .Range("A" & Rows.Count).End(xlUp).Row + 1
For I = 0 To ListBox1.ListCount - 1
.Range("A" & Uf) = ListBox1.List(I, 0) 'Columna 1
.Range("B" & Uf) = ListBox1.List(I, 1) 'Columna 2
.Range("C" & Uf) = ListBox1.List(I, 2) 'Columna 3
Uf = Uf + 1
Next I
End With
ListBox1.Clear
End Sub
Private Sub CommandButton5_Click()
Unload Me
End Sub
Private Sub ListBox1_Click()
TextBox1.Text = ListBox1.List(ListBox1.ListIndex, 0)
TextBox2.Text = ListBox1.List(ListBox1.ListIndex, 1)
TextBox3.Text = ListBox1.List(ListBox1.ListIndex, 2)
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Limpiar
End Sub
Comentarios sobre la versión: 1.0 (1)