Solved

sorting special multicolumn listbox

Posted on 2014-04-05
7
246 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

627 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