PDA

View Full Version : Automatic Sort On double Click



hardeep
08-04-2010, 08:15 AM
Hello Experts

Is it Possible to Sort the Data upon Double Click

Means if i Double Click on A1 Header it Sort the Whole Data By column A

If i Double Click on B1 it Sort by column B, If Double Click on G1 it Sort the Data by Column G

what ever i Double Click on any Column It Sort by that Column

Regards

Hardeep

hardeep
08-04-2010, 08:36 AM
I found this Code After Google Search


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Range("A:Z").Select 'this is the sort range
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Target.Select

End Sub


Its Working for Only Column A not for Others

Regards

Hardeep

slamet Harto
08-04-2010, 08:41 AM
xl2003


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Row <> 1 Then Exit Sub
Rows("2:65536").Sort Key1:=Cells(2, Target.Column), Order1:=xlAscending, Header:=xlNo
End Sub

hardeep
08-04-2010, 08:45 AM
xl2003

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _ Cancel As Boolean)
If Target.Row <> 1 Then Exit Sub
Rows("2:65536").Sort Key1:=Cells(2, Target.Column), _
Order1:=xlAscending, Header:=xlNo
End Sub


Hey Thanks Dude:beerchug:

Thanks 4 :help Me

hardeep
08-04-2010, 07:59 PM
One More Question

How to Available this Code in all Workbook and Worksheets

See the Attached

It Works for First Sheet i.e. "AHMADABAD" not for Others

slamet Harto
08-05-2010, 03:35 AM
have you put the code in thisworkbook module?
i've limitation (internet quota) to see your attachment, sorry

YasserKhalil
08-05-2010, 04:11 AM
Mr. Hardeep
try the following attachement

dragon
08-05-2010, 06:38 AM
Here's an alternative way of doing that if anyone's interested. It's a workbook with some VBA code created by Dave Peterson that I've found very useful over the years.

If you click on the header row it will flip the view between ascending and descending order.

To set it up for the first time, in VBA Editor go into the SetupOneTime routine and change iCol to equal the number of columns for your data.

Then change iCol to equal the number of columns for your data in the SortTable routine.

Then run the SetupOneTime macro.

hardeep
08-06-2010, 07:52 PM
First of all , I am Really Sorry for Late Reply

Thanks everybody,

It works in only one particular workbook,

I need to Work in every workbook or Worksheet, Same as ADD-IN or Macros Works

Or how can i Enter this Code in My PERSONAL.XLSX, SO that can it works on every Worksheet