Mejorar el diseño del formulario "cafetería"

Necesito desarrollar un mejoramiento del diseño del formulario "para Dante Amor".

2 respuestas

Respuesta
1

Te anexo las macros

Para cargar los productos:

Private Sub UserForm_Activate()
'Por.Dante Amor
    'cargar los productos en el combo
    ingreso = Format(Date, "dd/mm/yyyy")
    Set h5 = Sheets("PRODUCTOS")
    ComboBox1.ColumnCount = 2
    For i = 2 To h5.Range("A" & Rows.Count).End(xlUp).Row
        ComboBox1.AddItem h5.Cells(i, "A")
        ComboBox1.List(ComboBox1.ListCount - 1, 1) = h5.Cells(i, "B")
    Next
End Sub

Para pasar los productos al "carrito" al listbox:

Private Sub CommandButton5_Click()
'Por.Dante Amor
    If ComboBox1 = "" Then Exit Sub
    If TextBox1 = "" Or Not IsNumeric(TextBox1) Then
        MsgBox "captura un valor en cantidad", vbExclamation
        TextBox1.SetFocus
        Exit Sub
    End If
    '
    Set h5 = Sheets("PRODUCTOS")
    f = ComboBox1.ListIndex + 2
    precio = h5.Cells(f, "B")
    ListBox1.AddItem ComboBox1.List(ComboBox1.ListIndex, 0)
    ListBox1.List(ListBox1.ListCount - 1, 1) = ComboBox1.List(ComboBox1.ListIndex, 1)
    ListBox1.List(ListBox1.ListCount - 1, 2) = TextBox1
    importe = CDbl(ComboBox1.List(ComboBox1.ListIndex, 1)) * CDbl(TextBox1)
    ListBox1.List(ListBox1.ListCount - 1, 3) = importe
    '
    For i = 0 To ListBox1.ListCount - 1
        wtot = wtot + CDbl(ListBox1.List(i, 3))
    Next
    TOTAL = wtot
    ComboBox1 = ""
    TextBox1 = ""
    ComboBox1.SetFocus
End Sub

Para pasar los datos a la hoja:

Private Sub CommandButton2_Click()
'Por.Dante Amor
    Set h4 = Sheets("CAFETERIA")
    u = h4.Range("A" & Rows.Count).End(xlUp).Row + 1
    For i = 0 To ListBox1.ListCount - 1
        h4.Cells(u, "A") = CDate(ingreso)
        h4.Cells(u, "B") = ListBox1.List(i, 0)
        h4.Cells(u, "C") = ListBox1.List(i, 1)
        h4.Cells(u, "D") = ListBox1.List(i, 2)
        h4.Cells(u, "E") = ListBox1.List(i, 3)
        u = u + 1
    Next
    TOTAL = ""
    ComboBox1 = ""
    TextBox1 = ""
    ListBox1.Clear
    ComboBox1.SetFocus
End Sub

Antes de pasar los datos y quieres corregir un registro, lo puedes borrar con lo siguiente:

Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
'Por.Dante Amor
    'elimina el registro presionando la tecla Supr
    If ListBox1.ListIndex = -1 Then Exit Sub
    If KeyCode = 46 Then
        ListBox1.RemoveItem (ListBox1.ListIndex)
    End If
End Sub

Respuesta

El sistema me había sugerido contestar ésta pregunta, pero he visto que aparte de ir dirigida a Dante, la ha resuelto con la solvencia de un maestro, al que no se me ocurriría ni siquiera imitar. Saludos Karper y Dante> Jacinto

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas