Solved

sorting special multicolumn listbox

Posted on 2014-04-05
7
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 40

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 40

Expert Comment

by:als315
ID: 39980865
Can you upload sample worksheet?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

756 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