Sumar precios de una columna de listbox
Encontré en la red un formulario que podría usar en un kiosko que tengo, pero este no funciona bien... Da un error al cargar más de 1 articulo.. ¿no suma los totales podrías darme una mano con esto por favor? Le puse un @ al principio a la línea que da el error. Desde ya muchas gracias! Ya llevo un mes más o menos leyendo cosas y no puedo dar con la solución :(
Private Sub CommandButton1_Click() 'Registrar producto y capturar cantidad 'Declaramos variables Dim strDescripcion As String Dim intCantidad As Double Dim doublePUnitario As Double Dim intTotal As Double ' 'En caso de error 'On Error GoTo ErrorHandler ' With Application.WorksheetFunction ' 'Usamos BUSCARV para encontrar el detalle del producto ' strDescripcion = . VLookup(CDbl(Me. TextBox1. Value), PRODUCTOS.Range("A:C"), 2, 0) ' intCantidad = TextBox2 'InputBox(strDescripcion & vbNewLine & vbNewLine & "Ingresa la cantidad.", "Cantidad", 1) 'If intCantidad = TextBox2.Value Then GoTo ErrorHandler 'Llenamos el ListBox '...CÓDIGO Me.ListBox1.AddItem Me.TextBox1.Value '...DESCRIPCIÓN ListBox1.List(ListBox1.ListCount - 1, 1) = strDescripcion '...CANTIDAD ListBox1.List(ListBox1.ListCount - 1, 2) = .Text(intCantidad, "#,##0") '...P.UNITARIO doublePUnitario = .VLookup(CDbl(Me.TextBox1.Value), PRODUCTOS.Range("A:C"), 3, 0) ListBox1.List(ListBox1.ListCount - 1, 3) = .Text(doublePUnitario, "#.##0,00;-#.##0,00") '...SUB-TOTAL intTotal = doublePUnitario * intCantidad ListBox1.List(ListBox1.ListCount - 1, 4) = .Text(intTotal, "#.##0,00;-#.##0,00") '...ETIQUETAS Me.lblProductos = .Text(CInt(Me.lblProductos) + CInt(intCantidad), "#,##0") @ Me.lblTotal = .Text(CDbl(Me.lblTotal) + CDbl(intTotal), "$#.##0,00;-$#.##0,00") Me.TextBox1.Value = "" Me.TextBox1.SetFocus ' End With Exit Sub ' 'ErrorHandler: ' 'MsgBox "Ha ocurrido un error: " & Err.Description, vbExclamation, "TIEN21" ' Me.TextBox1.Value = "" Me.TextBox1.SetFocus '********************************** End Sub ' Private Sub CommandButton4_Click() Unload Me End Sub ' Private Sub CommandButton5_Click() 'Guardar compra en tabla Dim i As Variant Dim j As Variant Dim TransRowRng As Range Dim NewRow As Integer ' With VENTAS ' For i = Me.ListBox1.ListCount To 1 Step -1 ' Set TransRowRng = ThisWorkbook.Worksheets("VENTAS").Cells(1, 1).CurrentRegion NewRow = TransRowRng.Rows.Count + 1 .Cells(NewRow, 1).Value = Date .Cells(NewRow, 2).Value = Me.txtConsec.Value ' For j = 0 To 4 ' .Cells(NewRow, j + 3).Value = Me.ListBox1.List(Me.ListBox1.ListCount - i, j) ' Next j ' Next i ' End With ' 'MsgBox "Registros guardados con éxito.", vbInformation, "EXCELeINFO" Sheets("opera").Select Columns("A39:E39").ClearContents Unload Me frmVenta.Show End Sub Private Sub CommandButton6_Click() 'Eliminar producto capturado erroneamente. ' ListBox1.RemoveItem ListBox1.ListIndex 'ARTICULOS 'Dim i, tot As Double 'For i = 0 To ListBox1.ListCount - 1 'tot = tot + Val(ListBox1.List(i, 3)) 'Next i 'lblTotal = tot 'TOTAL ' If ListBox1.ListIndex > -1 Then 'si se ha seleccionado algo ' Cells(ListBox1.ListIndex + 1, 5) = "" ' Cells(ListBox1.ListIndex + 1, 2) = "" ' Cells(ListBox1.ListIndex + 1, 3) = "" ' Cells(ListBox1.ListIndex + 1, 4) = "" ' Cells(ListBox1.ListIndex + 1, 5) = "" ' ListBox1.RemoveItem (ListBox1.ListIndex) End If End Sub ' Private Sub UserForm_Initialize() 'textbox2 valor default TextBox2 = "1" Dim intConsecutivo As String ' Me.ListBox1.ColumnCount = 5 Me.ListBox1.ColumnWidths = "70 pt; 150 pt; 55 pt; 60 pt; 60 pt" Me.txtFecha.Value = Date ' intConsecutivo = VENTAS.Range("I1").Value ' If intConsecutivo = "CONSECUTIVO" Then ' Me.txtConsec = 1 ' Else ' Me.txtConsec = intConsecutivo + 1 ' End If End Sub Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then TextBox1.SetFocus End If End Sub
1 Respuesta
Respuesta de Dante Amor
1