ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sort list (https://www.excelbanter.com/excel-programming/316233-sort-list.html)

Kirk Groome

Sort list
 
I have a list that I fill from information from other sheets and then I want
to sort the list how would I do that. I have tried and can't seem to get
sort to work.

Here is my code.

Private Sub CommandButton1_Click()
Dim wrksht As Worksheet
Dim oListCol As ListRow
Dim oList As ListObject
Dim oListSort As ListColumn
Dim sWork As String
Dim ListRange As Range

Set wrksht = ActiveWorkbook.Worksheets("Reports")
Set oList = wrksht.ListObjects(1)
For Each lsheet In Sheets
If (lsheet.Name < "Reports") Or (lsheet.Name < "Panels List") Or
(lsheet.Name < "Master") Then
Set oListCol = wrksht.ListObjects("list1").ListRows.Add
sWork = "=text('" & lsheet.Name & "'!b2,""#"")"
oListCol.Range.Cells(1, 1).Value = sWork
oListCol.Range.Cells(1, 2).Formula = "='" & lsheet.Name & "'!b112"
oListCol.Range.Cells(1, 3).Formula = "='" & lsheet.Name & "'!c112"
oListCol.Range.Cells(1, 4).Formula = "='" & lsheet.Name & "'!b113"
oListCol.Range.Cells(1, 5).Formula = "='" & lsheet.Name & "'!c113"
oListCol.Range.Cells(1, 6).Formula = "='" & lsheet.Name & "'!b114"
oListCol.Range.Cells(1, 7).Formula = "='" & lsheet.Name & "'!c114"
oListCol.Range.Cells(1, 8).Formula = "='" & lsheet.Name & "'!b115"
oListCol.Range.Cells(1, 9).Formula = "='" & lsheet.Name & "'!c115"
End If
Next
' want to sort list box now on column 1
End Sub


Thanks
Kirk Groome



Simon Lloyd[_608_]

Sort list
 

Hi Kirk,

You could try these, the first sorts column A in ascending forma
assuming no header to the column the second assumes a header to th
column.

hope they help!

Simon

Columns("A:A").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
_
DataOption1:=xlSortNormal

Columns("A:A").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
_
DataOption1:=xlSortNorma

--
Simon Lloy
-----------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...nfo&userid=670
View this thread: http://www.excelforum.com/showthread.php?threadid=27677



All times are GMT +1. The time now is 08:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com