sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,421
- Office Version
- 2016
- Platform
- Windows
I'm using this to populate a Listbox on a Userform;
Column F houses either blank, numbers or the word "COMPLETED" - I'd like the Listbox to be sorted in a ascending order starting with the lowest number, so zero upwards. If the cell is empty or contains the word "COMPLETED" then I want the item to be placed at the bottom.
Is this possible?
Code:
Private Sub UserForm_Initialize()
Dim c1 As Range
Dim FindString As String
On Error GoTo HandleError
Application.ScreenUpdating = False
Sheet19.Activate
With Sheet19
For Each c1 In .Range("A2", .Range("a" & Rows.count).End(xlUp))
If c1.Value <> "" Then ComboAREA.AddItem c1.Value
Next c1
End With
With Sheet19
For Each c2 In .Range("B2", .Range("B" & Rows.count).End(xlUp))
If c2.Value <> "" Then ComboGROUP.AddItem c2.Value
Next c2
End With
With ComboBox2
.AddItem "CAC"
.AddItem "FEC"
End With
Dim j As Long
Dim x As Long
ReDim a(1 To 13, 2 To 5000) As Variant
x = 1
For j = 2 To 5000
If Not Range("A" & j).Value = vbNullString Then
x = x + 1
a(1, x) = Range("A" & j).Value
a(2, x) = Range("B" & j).Value
a(3, x) = Range("C" & j).Value
a(4, x) = Range("D" & j).Value
a(5, x) = Range("E" & j).Value
a(6, x) = Range("F" & j).Value
a(7, x) = Range("G" & j).Value
a(8, x) = Range("H" & j).Value
' a(9, x) = Range("I" & j).Value
' a(10, x) = Range("J" & j).Value
' a(11, x) = Range("K" & j).Value
' a(12, x) = Range("L" & j).Value
a(13, x) = j
End If
Next j
If x > 1 Then
ReDim Preserve a(1 To 13, 2 To x)
Me.ListBox1.List = Application.Transpose(a)
'ListBox1.ColumnWidths = ";;;;;;"
End If
Me.EnableEvents = True
'sortListBox
ListBox1.Enabled = False
ListBox1.BackColor = &H8000000F
ListBox1.ForeColor = &H808080
Me.BackColor = RGB(0, 65, 123)
Frame1.BackColor = RGB(0, 65, 123)
Frame2.BackColor = RGB(0, 65, 123)
Frame3.BackColor = RGB(0, 65, 123)
Frame1.ForeColor = &HFFFFFF
Frame2.ForeColor = &HFFFFFF
Frame3.ForeColor = &HFFFFFF
Label1.BackColor = RGB(0, 65, 123)
Label11.BackColor = RGB(0, 65, 123)
Label2.BackColor = RGB(0, 65, 123)
Label3.BackColor = RGB(0, 65, 123)
Label4.BackColor = RGB(0, 65, 123)
Label5.BackColor = RGB(0, 65, 123)
Label6.BackColor = RGB(0, 65, 123)
Label22.BackColor = RGB(0, 65, 123)
Label23.BackColor = RGB(0, 65, 123)
Label24.BackColor = RGB(0, 65, 123)
Label25.BackColor = RGB(0, 65, 123)
Label26.BackColor = RGB(0, 65, 123)
Label27.BackColor = RGB(0, 65, 123)
Label28.BackColor = RGB(0, 65, 123)
Label8.BackColor = RGB(0, 65, 123)
Label9.BackColor = RGB(0, 65, 123)
Label10.BackColor = RGB(0, 65, 123)
Label12.BackColor = RGB(0, 65, 123)
Label13.BackColor = RGB(0, 65, 123)
Label14.BackColor = RGB(0, 65, 123)
Label15.BackColor = RGB(0, 65, 123)
Label16.BackColor = RGB(0, 65, 123)
Label17.BackColor = RGB(0, 65, 123)
Label18.BackColor = RGB(0, 65, 123)
Label19.BackColor = RGB(0, 65, 123)
Label20.BackColor = RGB(0, 65, 123)
Label21.BackColor = RGB(0, 65, 123)
CommandButton1.BackColor = RGB(0, 65, 123)
CommandButton2.BackColor = RGB(0, 65, 123)
CommandButton3.BackColor = RGB(0, 65, 123)
CommandButton1.ForeColor = &HFFFFFF
CommandButton2.ForeColor = &HFFFFFF
CommandButton3.ForeColor = &HFFFFFF
CommandButton4.ForeColor = &HFFFFFF
CommandButton4.BackColor = RGB(0, 65, 123)
OptionButton3.Value = True
Exit Sub
HandleError:
ErrorHandle Err, Erl(), "TrainingFrm - UserForm_Initialize"
Resume Next
End Sub
Column F houses either blank, numbers or the word "COMPLETED" - I'd like the Listbox to be sorted in a ascending order starting with the lowest number, so zero upwards. If the cell is empty or contains the word "COMPLETED" then I want the item to be placed at the bottom.
Is this possible?