No me aparecen 2 columnas en el listbox

De nuevo para realizar un pregunta la cual no la he podido resolver y la manera para que me aparezcan 2 columnas en un listbox adjunto imágenes para hacerme entender mejor

De acuerdo a la imagen trengo 2 listbox los cuales agreo información por medio de ese botón AGREGAR y los recibe el otro listbox que lo requiero con 2 columnas. Al seleccionar el dato del llistbox 1 me aparece

La eqtiqueta para ingresar cantidad y ese dato que registro es que requiero que aparezca en el otro list box debajo de la columna que dice PESO POR GRS ... Adjunto código para verificar donde esta mi falla gracias

Private Sub UserForm_Initialize()
Dim X, numrec As Long
X = 2
Do While Hoja5.Cells(X, 1) <> Empty
    X = X + 1
Loop
numrec = X - 0
    If Hoja2.Cells(2, 1) = Empty Then
       Lbl_consecutivo = 0 + 1
    Else
        Lbl_consecutivo = Hoja5.Cells(numrec, 1) + 1
    End If
'Dim intConsecutivo As String
'intConsecutivo = Recetas.Range("X1").Value
''
'If intConsecutivo = "CONSECUTIVO" Then
'    '
'    Me.Lbl_consecutivo = 1
'    '
'Else
'    '
'    Me.Lbl_consecutivo = intConsecutivo + 1
'    '
'End If
a = Sheets(Hoja2.Name).Range("A2:K" & Sheets(Hoja2.Name).Range("A" & Rows.Count).End(3).Row).Value ' se carga todo en una matriz
 With ListBox2
 .List = a ' la matriz queda cargada para mostrar
 .ColumnCount = 2 ' numero de columna de la hojas amostrar
 .ColumnWidths = "0pt; 20pt" 'columna 0  no se muestre y segunda columna con dimencion 20
'.ColumnWidths = "70 pt; 150 pt; 55 pt; 60 pt; 60 pt"
 End With
End Sub
Private Sub CommandButton3_Click()
Dim X, numrec As Long
Dim final As Long
Dim i, fila As Integer
      For fila = 1 To 1000
          If Hoja5.Cells(fila, 1) = "" Then
          final = fila
          Exit For
          End If
      Next
'
'      For i = 0 To ListBox1.ListCount - 1
'         Hoja5.Cells(final, 8) = Me.ListBox1.List(i, 0)
'         Hoja5.Cells(final, 9) = Me.ListBox1.List(i, 1)
'        final = final + 1
'
'      Next
X = 2
Do While Hoja5.Cells(X, 1) <> Empty
    X = X + 1
Loop
numrec = X - 1
    If Hoja5.Cells(2, 1) = Empty Then
       Lbl_consecutivo = 0 + 1
    Else
        Lbl_consecutivo = Hoja5.Cells(numrec, 1) + 1
    End If
    Sheets(Hoja5.Name).Select
    final = GetNuevoR(Hoja5)
  For i = 0 To ListBox1.ListCount - 1
         Hoja5.Cells(final, 1) = Val(Lbl_consecutivo)
         Hoja5.Cells(final, 2) = Txt_codreceta.Text
         Hoja5.Cells(final, 3) = Txt_tireceta.Text
         Hoja5.Cells(final, 4) = Txt_nomreceta.Text
         Hoja5.Cells(final, 8) = Me.ListBox1.List(i, 0)
         Hoja5.Cells(final, 9) = Me.ListBox1.List(i, 1)
        final = final + 1
   Next
        limpiacontroles
        ' Hoja4.Cells(Final, 11) = "-" & Me.ListBox1.List(i, 0) * CostoUnitario 'Obtengo el costo total
        'Cells(final, 5) = Format(txt_precio1.Text, "$ #,##0.00")
End Sub

1 Respuesta

Respuesta
1

Me parece que te faltó el código para el botón "AGREGAR".

También indica cómo se llama el listbox de la izquierda y cómo se llama el de la derecha.

Estoy revisando tu userform.

Y supongo que cuando presionas el botón "Agregar" aparece un inputbox.

Lo que te recomiendo es agregar un textbox en tu formulario, en lugar de aparecer un inputbox.

Precisamente para eso es tu formulario, para ingresar valores. Tendrías mejor control con un textbox que con un inputbox. Mira el siguiente ejemplo:

Entonces cuando presiones el botón "Agregar", pasarías al listbox2, el dato del listbox1 y el dato del textbox.

Si estás de acuerdo con mi propuesta, prueba lo siguiente:

Private Sub CommandButton1_Click()  'Ajusta el nombre de tu botón agregar
  'Agregar
  'Por Dante Amor
  '
  'Validaciones
  If ListBox1.ListIndex = -1 Then
    MsgBox "Selecciona un registro del listbox1"
    Exit Sub
  End If
  'Ajusta el textbox5 por el nombre de tu textbox
  If TextBox5.Value = "" Or Not IsNumeric(TextBox5.Value) Then
    MsgBox "Captura una cantidad válida"
    TextBox5.SetFocus
    Exit Sub
  End If
  '
  'Pasa los datos al listbox2
  With ListBox2
    .ColumnCount = 2
    .ColumnWidths = "50;20"   'ajusta el ancho de cada columna
    .AddItem ListBox1.List(ListBox1.ListIndex, 0)
    .List(.ListCount - 1, 1) = TextBox5.Value 'Ajusta el textbox5 por el nombre de tu textbox
  End With
  '
  'inicializa valores
  TextBox5.Value = ""
  ListBox1.ListIndex = -1
End Sub

Agregue unos comentarios en el código para que ajustes los nombres y valores.

Avísame cualquier duda.

¡Gracias Totales ! perdón  por no haber  valorado tan valioso aporte a la tecnología estoy tan metido en el script que ser me paso valorarla de nuevo gracias maestro  

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas