Controlar valor repetido en un listbox que venga de otro listbox

Bueno sigo trabajando con listbox y me he encontrado con el siguiente problema que no puedo solucionar.

Tengo dos formularios y dos listbox cado uno con 10 columnas (foringreso con un listbox2 / fordatoingresar con un un listbox1).

Quiero que al momento de pasar un dato(sin que se borre el dato a pasar) del fordatoingresar desde listbox1 al foringreso - listbox2(este es el que recibe el dato), me verifique si el dato ya esta pasado y me pregunte si es que lo quiero volver a pasar. Esto seria comparando 1 columna en especifico de cada listbox (listbox2-columna 0 o additems / listbox1 - columna 4) estas contienen datos iguales, las demas columnas no todos los datos a pasar son iguales.

Con este codigo obtengo los datos del fordatoingresar -listbox1:

Me. ListBox1. AddItem Cells(i, 20) 'ESTADO
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = Cells(i, 19) 'DIFERENCIA
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = Cells(i, 13) 'CANTIDAD
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = Cells(i, 12) 'UNIDAD DE MEDIDA
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = Cells(i, 8) ' CODIGO
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = Cells(i, 9) 'MARCA
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = Cells(i, 10) 'MODELO
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = Cells(i, 11) 'DESCRIPCION
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 8) = Cells(i, 14) 'PRECIO UNIDAD
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 9) = Cells(i, 15) 'PRECIO TOTAL

Este es el foringreso con el listbox2 (para pasar los datos)

* Este es el codigo que estoy utilizando, para pasar los datos al foringreso - listbox2:

If ListBox1.List(ListBox1.ListIndex, 0) = "ARRIBO" Then
MsgBox ("ARTICULO YA INGRESADO")
Exit Sub
End If

cantidad = TextBox2
precio = ListBox1.List(i, 8)
tot = cantidad * precio
ptotal = tot

With RINGRESO
If (.ListBox2.List.Contains(ListBox1.List(ListBox1.ListIndex, 4))) Then
RESPUESTA = MsgBox("¿DESEA CARGAR DE NUEVO EL MISMO ARTICULO?", vbYesNo)
If RESPUESTA = vbYes Then
End If
If RESPUESTA = vbNo Then
Exit Sub
End If
End If

For i = 0 To ListBox1.ListCount - 1

If ListBox1.Selected(i) Then
. ListBox2. AddItem ListBox1.List(i, 4)
.ListBox2.List(.ListBox2.ListCount - 1, 1) = ListBox1.List(i, 5)
.ListBox2.List(.ListBox2.ListCount - 1, 2) = ListBox1.List(i, 6)
.ListBox2.List(.ListBox2.ListCount - 1, 3) = TextBox3.Value
.ListBox2.List(.ListBox2.ListCount - 1, 4) = ListBox1.List(i, 7)
.ListBox2.List(.ListBox2.ListCount - 1, 5) = ListBox1.List(i, 3)
.ListBox2.List(.ListBox2.ListCount - 1, 6) = ListBox1.List(i, 2)
.ListBox2.List(.ListBox2.ListCount - 1, 7) = TextBox2.Value
.ListBox2.List(.ListBox2.ListCount - 1, 8) = ListBox1.List(i, 8)
.ListBox2.List(.ListBox2.ListCount - 1, 9) = ptotal
End If
Next
End With

este es el listbox que recibe los datos.

1 Respuesta

Respuesta
1

Envíame tu archivo [email protected] 

Te envié el archivo, espero se pueda lograr lo que solicito.

gracias de antemano

Te anexo el código.

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'POR TEMP01
 For i = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(i) Then
            For j = 0 To RINGRESO.ListBox2.ListCount - 1
                If ListBox1.List(i, 4) = RINGRESO.ListBox2.List(j, 0) Then
                    wr = MsgBox("YA EXISTE EL CÓDIGO " & ListBox1.List(i, 4) + Chr(13) + "DESEA AGREGAR OTRO IGUAL?", vbInformation + vbYesNo, "AVISO")
                    If wr = vbNo Then
                    Exit Sub
                   End If
                End If
            Next j
            RINGRESO.ListBox2.AddItem ListBox1.List(i, 4)
            RINGRESO.ListBox2.List(RINGRESO.ListBox2.ListCount - 1, 1) = ListBox1.List(i, 5)
            RINGRESO.ListBox2.List(RINGRESO.ListBox2.ListCount - 1, 2) = ListBox1.List(i, 6)
            RINGRESO.ListBox2.List(RINGRESO.ListBox2.ListCount - 1, 3) = ListBox1.List(i, 7)
            End If
    Next
End Sub

Te envié el archivo.

Valora respuesta la para finalizar saludos!

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas