Is this possible?? Please help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to be able to click on my column titles to have the rows sorted by the
information in those colums.

Like in a windows file, Click on date created or auther etc.

So is it possible?? and does this have a name??

Please help i an sooo stuck.
 
Right click sheet tab>view code>insert this>modify to suit your range.
Now when you double click on any cell in the desired column the range will
be sorted by that column.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
ac = ActiveCell.Column
Range("A2:B6").Sort Key1:=Cells(3, ac), Order1:=xlAscending
End Sub
 
I need to be able to click on my column titles to have the rows sorted by the
information in those colums.

Like in a windows file, Click on date created or auther etc.

So is it possible?? and does this have a name??

Please help i an sooo stuck.

This VBA Event macro will do:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1:F1")) Is Nothing Then
Range("A1:F100").Sort Key1:=Target, Order1:=xlAscending, Header:=
_
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End Sub

It assumes that your titles are in A1:F1 and the table will not be
longer than A1:F100. Change these to suit. Then:

Right click on the sheet tab. Choose View Code... This will take you
to the VBA IDE. Paste the above code in the window.

HTH
Kostis Vezerides
 
Back
Top