Excel - UserForm_Initialize() - need idea to improve the code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • silentbuddha
    New Member
    • Mar 2008
    • 2

    #1

    Excel - UserForm_Initialize() - need idea to improve the code

    Private Sub UserForm_Initia lize()

    '----------- POPULATE LISTBOX 1 -----------

    With ListBox1

    .AddItem "--none--"
    .AddItem "Account Maintenance"
    .AddItem "Change Service Status"
    .AddItem "Credit and Collections"

    '----------- SORT LISTBOX 1 ----------

    For i = 0 To .ListCount - 2
    For j = i + 1 To .ListCount - 1
    If .List(i) > .List(j) Then
    Temp = .List(j)
    .List(j) = .List(i)
    .List(i) = Temp
    End If
    Next j
    Next i

    End With

    '----------- POPULATE LISTBOX 2 -----------

    With ListBox2

    .AddItem "--none--"
    .AddItem "Activation "
    .AddItem "Support Policy"
    .AddItem "Memo"

    '------- SORT LISTBOX 2 -------


    For i = 0 To .ListCount - 2
    For j = i + 1 To .ListCount - 1
    If .List(i) > .List(j) Then
    Temp = .List(j)
    .List(j) = .List(i)
    .List(i) = Temp
    End If
    Next j
    Next i

    End With

    '----------- POPULATE LISTBOX 3 -----------

    With ListBox3

    .AddItem "--none--"
    .AddItem "Existing Account"
    .AddItem "New Account"
    .AddItem "New Account - Ptentials"


    '------- SORT LISTBOX 3 -------


    For i = 0 To .ListCount - 2
    For j = i + 1 To .ListCount - 1
    If .List(i) > .List(j) Then
    Temp = .List(j)
    .List(j) = .List(i)
    .List(i) = Temp
    End If
    Next j
    Next i

    End With

    '----------- SET FIRST ITEM OF LISTBOXES TO BE SELECTED BY DEFAULT ----------
    ListBox1 = ListBox1.List(0 )
    ListBox2 = ListBox2.List(0 )
    ListBox3 = ListBox3.List(0 )


    End Sub
Working...