Solved

sorting special multicolumn listbox

Posted on 2014-04-05
7
238 Views
Last Modified: 2014-04-05
excel vba
userform
listbox

Need this sorted by column "Col1"  second column

I have data i a listbox that looks like this:
Col0          Col1
Pumps      (3)
Motors      (5)
Fans          (63)
Knives       (1)
Pullys        (101)

I need it to look like:   descending order..please
Col0          Col1
Pullys        (101)
Fans          (63)
Motors      (5)
Pumps      (3)
Knives       (1)


'=====================================================================================
    Dim i As Long
    Dim j As Long
    Dim sTemp As String
    Dim sTemp2 As String
    Dim sTemp3 As String
    Dim sTemp4 As String
    Dim sTemp5 As String
    Dim sTemp6 As String
    Dim LbList As Variant
'
    LbList = Me.ListBox1.List
    For i = LBound(LbList, 1) To UBound(LbList, 1)
        For j = i + 1 To UBound(LbList, 1)
            If LbList(i, 1) > LbList(j, 1) Then
 
                sTemp = LbList(i, 0)
                LbList(i, 0) = LbList(j, 0)
                LbList(j, 0) = sTemp
 
                sTemp2 = LbList(i, 1)
                LbList(i, 1) = LbList(j, 1)
                LbList(j, 1) = sTemp2
 
 
 
            End If
        Next j
    Next i

Open in new window




or some other suggested code?

Thanks
fordraiders
0
Comment
Question by:fordraiders
  • 5
  • 2
7 Comments
 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
ID: 39980847
Are there parenthesis around number? In this case text ordering rules will work:
63,5,3,101,1
You should convert text to numbers (parenthesis should be removed) and then order as decreasing numbers
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39980859
Are there parenthesis around number?
yes
0
 
LVL 39

Expert Comment

by:als315
ID: 39980865
Can you upload sample worksheet?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:fordraiders
ID: 39980866
ok even after taking the parenthese out..it still will not sort correctly with the code above.
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39980867
i have data pulling in from our vpn servers...no i cant send the sheet..sorry
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39980903
ok,

i used an old routine:
http://www.ozgrid.com/forum/showthread.php?t=71509

works fine:
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39980904
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now