Auto data sort by clicking on column

G

Guest

Apparently I can set up a spreadsheet to sort data by placing hot key in the
column indicator cell. (Similar to the newest on top in outlook)
How do I do this??
 
G

Guest

Here's a small example where I have a table (with 1 row headers) over
Range A1:F7 << Post below code into the Sheet Module Code window.

Simply Right-Click on any Column Header Row (Row 1 in this case)
HTH

Jim May

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True
If Not Intersect(Target, Range("A1:F1")) Is Nothing Then
SortCol = ActiveCell.Column
With ActiveSheet.Range("A1").CurrentRegion
.Sort Key1:=Target.Value, Order1:=xlAscending, Header:=xlGuess,
OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End With
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top