Información sobre Resumen en ListBox

Busque en el foro pero no encontre algo similar a lo que quiero realizar con mi codigo, o bueno alguna idea como realizarlo, adjunto imagen de lo que hace mi busqueda de información la cual esta funcionando correctamente, la pregunta es ¿existe la posibilidad de realizar un resumen con la informacion mostrada?. Se observa que se repiten mucho algunos conceptos, ¿se puede resumir a un solo nombre y muestre la cantidad total de ese concepto?

Respuesta
1

Puedes poner el código con es que estás haciendo la carga en el listbox.

Muchas gracias Dante

Private Sub btn_Buscar_Click()
Dim Fila, Final As Integer
'Buscamos la última fila en la hoja de productos
Fila = 2
Do While Hoja16.Cells(Fila, 1) <> Empty
Fila = Fila + 1
Loop
Final = Fila - 1
If Me.ComboBox1.Value = Empty Then
Me.ListBox1.Clear
Me.txtFecha1 = Empty
Me.txtFecha2 = Empty
MsgBox "Seleccione un tecnico", vbExclamation, "Sistema Reporte Diario"
Me.ComboBox1.SetFocus
Exit Sub
ElseIf Me.txtFecha1 = Empty Then
Me.txtFecha1.SetFocus
MsgBox "Ingrese la fecha inicial", vbExclamation, "Sistema Reporte Diario"
Exit Sub
ElseIf Me.txtFecha2 = Empty Then
Me.txtFecha2.SetFocus
MsgBox "Ingrese la fecha final", vbExclamation, "Sistema Reporte Diario"
Exit Sub
End If

Me.ListBox1.Clear

'Mostrar Productos

items = Hoja16.Range("Consumibles").CurrentRegion.Rows.Count
For i = 2 To items
If Hoja16.Cells(i, 1).Value Like Me.ComboBox1 _
And CDate(Hoja16.Cells(i, 2).Value) >= CDate(Me.txtFecha1) _
And CDate(Hoja16.Cells(i, 2).Value) <= CDate(Me.txtFecha2) Then
Me.ListBox1.AddItem Hoja16.Cells(i, 2)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = Hoja16.Cells(i, 3)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = Hoja16.Cells(i, 8)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = Hoja16.Cells(i, 9)
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = Replace(Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3), ",", ".")
End If
Next i
Me.ComboBox1.SetFocus
Me.ComboBox1.SelStart = 0
Me.ComboBox1.SelLength = Len(Me.ComboBox1.Text)
'Sumatoria del total en columna Cantidad
For p = 0 To ListBox1.ListCount - 1
tot = tot + Val(ListBox1.List(p, 3))
Next p
txt_total = tot
Me.txt_total = Replace(txt_total, ",", ".")

Exit Sub

End Sub

Le sirvió mi código como se lo mande, o ¿requiere mas información?

Te anexo el código actualizado

Private Sub btn_Buscar_Click()
    Dim Fila, Final As Integer
    'Buscamos la última fila en la hoja de productos
    Fila = 2
    Do While Hoja16.Cells(Fila, 1) <> Empty
    Fila = Fila + 1
    Loop
    Final = Fila - 1
    If Me.ComboBox1.Value = Empty Then
    Me.ListBox1.Clear
    Me.txtFecha1 = Empty
    Me.txtFecha2 = Empty
    MsgBox "Seleccione un tecnico", vbExclamation, "Sistema Reporte Diario"
    Me.ComboBox1.SetFocus
    Exit Sub
    ElseIf Me.txtFecha1 = Empty Then
    Me.txtFecha1.SetFocus
    MsgBox "Ingrese la fecha inicial", vbExclamation, "Sistema Reporte Diario"
    Exit Sub
    ElseIf Me.txtFecha2 = Empty Then
    Me.txtFecha2.SetFocus
    MsgBox "Ingrese la fecha final", vbExclamation, "Sistema Reporte Diario"
    Exit Sub
    End If
    Me.ListBox1.Clear
    'Mostrar Productos
    items = Hoja16.Range("Consumibles").CurrentRegion.Rows.Count
    For i = 2 To items
        If Hoja16.Cells(i, 1).Value Like Me.ComboBox1 _
           And CDate(Hoja16.Cells(i, 2).Value) >= CDate(Me.txtFecha1) _
           And CDate(Hoja16.Cells(i, 2).Value) <= CDate(Me.txtFecha2) Then
            existe = False
            For j = 0 To ListBox1.ListCount - 1
                If ListBox1.List(j, 2) = Hoja16.Cells(i, 8) Then
                    Me.ListBox1.List(j, 3) = Me.ListBox1.List(j, 3) + Hoja16.Cells(i, 9)
                    Me.ListBox1.List(j, 3) = Replace(Me.ListBox1.List(j, 3), ",", ".")
                    existe = True
                    Exit For
                End If
            Next
            If existe = False Then
                Me.ListBox1.AddItem Hoja16.Cells(i, 2)
                Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = Hoja16.Cells(i, 3)
                Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = Hoja16.Cells(i, 8)
                Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = Hoja16.Cells(i, 9)
                Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = Replace(Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3), ",", ".")
            End If
        End If
    Next i
    Me.ComboBox1.SetFocus
    Me.ComboBox1.SelStart = 0
    Me.ComboBox1.SelLength = Len(Me.ComboBox1.Text)
    'Sumatoria del total en columna Cantidad
    For p = 0 To ListBox1.ListCount - 1
    tot = tot + Val(ListBox1.List(p, 3))
    Next p
    txt_total = tot
    Me.txt_total = Replace(txt_total, ",", ".")
    Exit Sub
End Sub

[no olvides valorar la respuesta.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas