• 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!

What am I doing wrong

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    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?
    Rule Number 1 - Assuming that you have a valid contract in place always try to get your poo onto your timesheet, provided that the timesheet is valid for your current contract and covers the period of time that you are billing for.

    I preferred version 1!

    #2
    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
    Rule Number 1 - Assuming that you have a valid contract in place always try to get your poo onto your timesheet, provided that the timesheet is valid for your current contract and covers the period of time that you are billing for.

    I preferred version 1!

    Comment


      #3
      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.
      It's about time I changed this sig...

      Comment


        #4
        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
        Rule Number 1 - Assuming that you have a valid contract in place always try to get your poo onto your timesheet, provided that the timesheet is valid for your current contract and covers the period of time that you are billing for.

        I preferred version 1!

        Comment


          #5
          Also just noticed you have spelt your variable wrong...

          vtiems = olb.List

          Use option explicit!
          It's about time I changed this sig...

          Comment


            #6
            Spotted that - cheers.

            Got it working. Took the brackets off from the line SortListBox (olb)
            Rule Number 1 - Assuming that you have a valid contract in place always try to get your poo onto your timesheet, provided that the timesheet is valid for your current contract and covers the period of time that you are billing for.

            I preferred version 1!

            Comment

            Working...
            X