• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Collapse

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "What am I doing wrong"

Collapse

  • BoredBloke
    replied
    Spotted that - cheers.

    Got it working. Took the brackets off from the line SortListBox (olb)

    Leave a comment:


  • MrRobin
    replied
    Also just noticed you have spelt your variable wrong...

    vtiems = olb.List

    Use option explicit!

    Leave a comment:


  • BoredBloke
    replied
    I think that is what I'm going to do - I was told that this should work but couldn't find out why it didn't

    Cheers

    Leave a comment:


  • MrRobin
    replied
    Why don't you just pass your array, vAllEnv, through the bubble sort first before it populates your list box, rather than trying to send the object itself.

    Leave a comment:


  • BoredBloke
    replied
    code in full

    Sub PopulateAll()

    Dim lgLastRow As Long
    Dim lgRowCounter As Long
    Dim intCounter As Integer
    Dim olb As MSForms.ListBox

    For intCounter = 0 To UBound(vAllEnv)
    Me.lstAll.AddItem (vAllEnv(intCounter))

    Next intCounter

    Set olb = frmOptions.lstAll

    SortListBox (olb)

    End Sub


    Sub SortListBox(ByRef olb As MSForms.ListBox)
    Dim vItems As Variant
    Dim i As Long
    Dim j As Long
    Dim vTemp As Variant

    vtiems = olb.List

    For i = LBound(vItems, 1) To UBound(vItems, 1) - 1
    For j = i + 1 To UBound(vItems, 1)
    If vItems(i, 0) > vItems(j, 0) Then
    vTemp = vItems(i, 0)
    vItems(i, 0) = vItems(j, 0)
    vItems(j, 0) = vTemp
    End If
    Next j
    Next i

    olb.Clear

    For i = LBound(vItems, 1) To UBound(vItems, 1)
    olb.AddItem vItems(i, 0)
    Next i
    End Sub

    Leave a comment:


  • BoredBloke
    started a topic What am I doing wrong

    What am I doing wrong

    Hi folks,

    I have a listbox in a form in excel which I have populated with data. I want to get this into alphabetical order. I have been trying to pass the contents of the listbox to a routine which carries out a bubble sort. Unfortunately it complains with an error saying 'object required'

    my listbox is called lstAll

    the routine it is going to is called

    sortListBox(olb as MSForms.listbox)

    What sytax should I use to get it to work? Is there something blindingly obvious I'm missing?
Working...
X