Ordenar listbox por orden alfabético

Tengo la macro siguiente; lo que necesito es que al momento de dar al botón imprimir me lo ordene ya sea en el listbox o en la hoja y que salga ordenado alfabéticamente en al segunda columna cuando se imprima. Muchas gracias.

Private Sub CommandButton3_Click()
'Por.Dante Amor
On Error Resume Next
    Set H = Sheets("Impresion de Inventario")
    H.Cells.Clear
    H.Range("A1") = Array("INVENTARIO NO.")
    H.Range("A3:B3:C3:D3") = Array("CATEGORIA", "ARTICULOS", "EXISTENCIA", "OBSERVACION")
    For i = 0 To ListBox1.ListCount - 1
        H.Cells(i + 5, "A") = ListBox1.List(i, 0)
        H.Cells(i + 5, "B") = ListBox1.List(i, 1)
        H.Cells(i + 5, "C") = ListBox1.List(i, 2)
    Next
        u = H.Range("A" & Rows.Count).End(xlUp).Row
    If u = 1 Then
        MsgBox "No se Encontraron Registros a Imprimir", vbCritical, "Error de Impresion"
    Else
Worksheets("Impresion de Inventario").Range("B1").Value = existencia_inventario.Label13.Caption 'referencia
H.Visible = True
H.PrintOut copies:=1, collate:=True
H.Visible = False
    End If
    On Error GoTo 0
    ThisWorkbook. Sabe
Unload Me
    Application. Quit
End Sub

1 Respuesta

Respuesta
2

Te anexo la macro actualizada para ordenar en la hoja antes de imprimir

Private Sub CommandButton3_Click()
'Por.Dante Amor
    Set h = Sheets("Impresion de Inventario")
    h.Cells.Clear
    h.Range("A1") = Array("INVENTARIO NO.")
    h.Range("A3:B3:C3:D3") = Array("CATEGORIA", "ARTICULOS", "EXISTENCIA", "OBSERVACION")
    For i = 0 To ListBox1.ListCount - 1
        h.Cells(i + 5, "A") = ListBox1.List(i, 0)
        h.Cells(i + 5, "B") = ListBox1.List(i, 1)
        h.Cells(i + 5, "C") = ListBox1.List(i, 2)
    Next
    u = h.Range("A" & Rows.Count).End(xlUp).Row
    If u = 3 Then
        MsgBox "No se Encontraron Registros a Imprimir", vbCritical, "Error de Impresion"
    Else
        h.Range("B1").Value = existencia_inventario.Label13.Caption 'referencia
        'Ordenar
        With h.Sort
            .SortFields.Clear
            .SortFields.Add Key:=h.Range("B5:B" & u), SortOn:=xlSortOnValues, _
                Order:=xlAscending, DataOption:=xlSortNormal
            .SetRange h.Range("A5:C" & u): .Header = xlGuess: .MatchCase = False
            .Orientation = xlTopToBottom: .SortMethod = xlPinYin: .Apply
        End With
        '
        h.Visible = True
        h.PrintOut copies:=1, collate:=True
        h.Visible = False
    End If
    ThisWorkbook.Save
    Unload Me
    Application.Quit
End Sub

.

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

.

Avísame cualquier duda

.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas