Advertisement
dave3009

DarioQ_Sort_EFF

Oct 7th, 2022
1,596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub UserForm_Initialize()
  2.  
  3. 'Create variables
  4. Dim j As Long
  5. Dim i As Long
  6. Dim temp As Variant
  7. Dim lstRw As Long
  8. Dim Sg As Worksheet
  9.  
  10. 'set variables values
  11. Set Sg = ThisWorkbook.Sheets("Data")
  12. lstRw = Sg.Range("U" & Rows.Count).End(xlUp).Row
  13.  
  14. 'populate listbox
  15. For i = 2 To lstRw
  16.     Me.ListBox1.AddItem Sg.Range("A" & i).Value
  17. Next i
  18.  
  19. 'Sort listBox in A-Z order
  20. With Me.ListBox1
  21.     For j = 0 To .ListCount - 2
  22.         For i = 0 To .ListCount - 2
  23.             If LCase(.List(i)) > LCase(.List(i + 1)) Then
  24.                 temp = .List(i)
  25.                 .List(i) = .List(i + 1)
  26.                 .List(i + 1) = temp
  27.             End If
  28.         Next i
  29.     Next j
  30. End With
  31.  
  32. End Sub
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement