ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Can I set up a sort by clicking on table a heading (https://www.excelbanter.com/excel-worksheet-functions/53604-can-i-set-up-sort-clicking-table-heading.html)

Aaron

Can I set up a sort by clicking on table a heading
 
I have a table I would like to set up to be sorted by clicking on a table
heading. Is that possible in Excel?


Thank you.

Roger Govier

Can I set up a sort by clicking on table a heading
 
Hi Aaron

Dave Peters has written some nice code to do this. It is available for
download at Debra Dalgleish's site
http://www.contextures.com/xlSort02.html#Rectangles

Regards

Roger Govier


Aaron wrote:
I have a table I would like to set up to be sorted by clicking on a table
heading. Is that possible in Excel?


Thank you.


Aaron

Can I set up a sort by clicking on table a heading
 
Perfect!!

Thank you.


Otto Moehrbach

Can I set up a sort by clicking on table a heading
 
Aaron
Yes. I take it that you want the sort key to be the column you clicked
on. You would use the Worksheet_SelectionChange event macro. You would
write code in that macro to check that the cell selected is one of the
header cells. If it isn't, do nothing. If it is, sort the table with that
column as the key column. An example macro follows. I assumed the table
had the range name "TheTable" and that the range of the headers is A1:E1.
Make the necessary changes. Post back if you need more. HTH Otto
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If IsEmpty(Target) Then Exit Sub
If Not Intersect(Target, Range("A1:E1")) Is Nothing Then
Range("TheTable").Sort Key1:=Target.Offset(1), Order1:=xlAscending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End If
End Sub
"Aaron" wrote in message
...
I have a table I would like to set up to be sorted by clicking on a table
heading. Is that possible in Excel?


Thank you.




Roger Govier

Can I set up a sort by clicking on table a heading
 
Well, thank Dave Peterson actually.

Apologies Dave for shortening your name in the previous post, Dave Peters
was a guy I was at University with.

Regards

Roger Govier


Aaron wrote:
Perfect!!

Thank you.


Dave Peterson

Can I set up a sort by clicking on table a heading
 
I'm sure he as a very nice person--even though he was missing that "ON"!

Roger Govier wrote:

Well, thank Dave Peterson actually.

Apologies Dave for shortening your name in the previous post, Dave Peters
was a guy I was at University with.

Regards

Roger Govier

Aaron wrote:
Perfect!!

Thank you.


--

Dave Peterson


All times are GMT +1. The time now is 06:40 AM.

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