Jeff1959
03-20-2009, 04:18 AM
Hi all, I have this code that I have used for a long time to sort by double clinking on a header. The problem is it does not work when I try to use it on a Excel formatted table. I'm new to VBA so figuring this one out has got me stumped. The error I keep getting is "Methoud Range of Object Worksheet Failed" Any help will be greatly appreciated. Heres the current code that Im using.
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim LRow As Long '-- D.McRitchie, 2006-04-01 double-click on column to sort
'Find last row in Column A with content
LRow = Cells(Rows.Count, 1).End(xlUp).Offset(0, 0).row
Rows("2:" & LRow).Sort Key1:=Cells(2, ActiveCell.Column), _
Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End Sub
Thanks
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim LRow As Long '-- D.McRitchie, 2006-04-01 double-click on column to sort
'Find last row in Column A with content
LRow = Cells(Rows.Count, 1).End(xlUp).Offset(0, 0).row
Rows("2:" & LRow).Sort Key1:=Cells(2, ActiveCell.Column), _
Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End Sub
Thanks