Solved

sorting special multicolumn listbox

Posted on 2014-04-05
7
237 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

744 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

12 Experts available now in Live!

Get 1:1 Help Now