![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Posts: 8
|
This should be an easy one. I have a basic list with multiple columns for each entry. I simply want to be able to click on a column heading and have the list sorted (alphbetically or numerically depending on the data) according to the data in that column. The only way I have discovered to do this is to put a button in each column, and record a macro. This is tedious and I know there must be an easier way. Any ideas? Your help is much appreciated.
Sincerely, Jeff |
|
|
|
|
|
#2 |
|
Join Date: May 2002
Posts: 73
|
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Row = 1 Then ActiveSheet.UsedRange.Sort Key1:=Target, Header:=xlYes Target(2, 1).Select End Sub |
|
|
|
|
|
#3 |
|
New Member
Join Date: May 2002
Posts: 8
|
Thanks Dimrod, but I have to admit that's a bit over my head. Any easier, non-coding, perhaps "built-in" solutions?
|
|
|
|
|
|
#4 | |
|
Join Date: May 2002
Posts: 73
|
Quote:
All you have to do is copy the code I posted and paste it in your worksheet's code module. You can get to the sheet's code module by right-clicking on the sheet tab and selecting ViewCode - the code module is the bit on the right hand side of the window that appears. That's not so difficult, is it? |
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Mar 2002
Location: Hellas
Posts: 553
|
Hello Jeffruiz
You can use the sort command in the data menu. Just select any cell in the list,go in the menu,data,sort and choose the sorting parameters (ascending or descending ) e.t.c. Does it look difficult ?
__________________
Best Regards Andreas
|
|
|
|
|
|
#6 |
|
New Member
Join Date: May 2002
Posts: 8
|
Dimrod,
Thank you very much. I just implemented your code and it works perfectly. I cannot thank you enough. Andreas, thank you for your input as well; I was looking for a one-step solution however. BTW, is there additional code I could enter so that if I double-click on a heading a second time, it would then sort it in reverse order? Best Regards, Jeff |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|