I want to make a button which when clicked will sort a data set (ascending) depending on which column was selected - is anyone able to share the code required to make this work?
I want to make a button which when clicked will sort a data set (ascending) depending on which column was selected - is anyone able to share the code required to make this work?
Try with this macro:
Regards,![]()
Sub Macro1() myCol = Selection.Column With ThisWorkbook.ActiveSheet .Cells.Sort Key1:=.Cells(1, myCol), Order1:=xlAscending, _ Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End With End Sub
Antronio
That is great thanks, forgive my 'green-ness' but is there away to define the data range? I would like to keep some of the bottom of the table rows constant.....
Yes, you could use this code:
Regards,![]()
Sub Macro1() Dim myCol As Integer, myRange As String myCol = Selection.Column myRange = "a1:f100" With ThisWorkbook.ActiveSheet .Range(myRange).Sort Key1:=.Cells(1, myCol), Order1:=xlAscending, _ Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End With End Sub
Antonio
Perfect thank you Antonio.
Final question on this topic - is there a way to reset the sorting so the table is back to the original display?
actually - will add another column and with a number rank and just sort that one.....
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks