Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Newbie sort problem - Please help

I've spent hours googling and searching this NG but have been unable to
solve my problem, so would much appreciate any help.

I'm trying to autosort two ranges in a worksheet, and it works fine if I
record a macro and run it, but if I try to run it as an "event", an error
message comes up:

“Run-time error ‘1004’:
The sort reference is not valid. Make sure that it’s within the data you
want to sort, and the first Sort By box isn’t the same or blank.”

Here is the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Sheets("Past Results").Select
Range("I2:L7").Select
Selection.Sort Key1:=Range("L3"), Order1:=xlDescending, Header:
=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("I9:K40").Select
Selection.Sort Key1:=Range("K10"), Order1:=xlDescending, Header:
=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A2").Select
End Sub

I would be grateful if someone could please tell me what I'm doing wrong.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Newbie sort problem - Please help

try this, watch for wordwrap

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
Set ws = Worksheets("Past Results")
With ws
.Range("I2:L7").Sort Key1:=ws.Range("L3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
.Range("I9:K40").Sort Key1:=ws.Range("K10"), Order1:=xlDescending,
Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
ws.Range("A2").Select
End Sub

--


Gary


"deej" wrote in message
5.104...
I've spent hours googling and searching this NG but have been unable to
solve my problem, so would much appreciate any help.

I'm trying to autosort two ranges in a worksheet, and it works fine if I
record a macro and run it, but if I try to run it as an "event", an error
message comes up:

“Run-time error ‘1004’:
The sort reference is not valid. Make sure that it’s within the data you
want to sort, and the first Sort By box isn’t the same or blank.”

Here is the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Sheets("Past Results").Select
Range("I2:L7").Select
Selection.Sort Key1:=Range("L3"), Order1:=xlDescending, Header:
=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("I9:K40").Select
Selection.Sort Key1:=Range("K10"), Order1:=xlDescending, Header:
=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A2").Select
End Sub

I would be grateful if someone could please tell me what I'm doing wrong.

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Newbie sort problem - Please help

"Gary Keramidas" <GKeramidasATmsn.com wrote in news:#AgjktfvHHA.4796
@TK2MSFTNGP04.phx.gbl:

try this, watch for wordwrap

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
Set ws = Worksheets("Past Results")
With ws
.Range("I2:L7").Sort Key1:=ws.Range("L3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
.Range("I9:K40").Sort Key1:=ws.Range("K10"), Order1:=xlDescending,
Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
ws.Range("A2").Select
End Sub


Thankyou very much Gary, worked perfectly.

--
Posted via a free Usenet account from http://www.teranews.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Newbie sort problem - Please help

you're welcome.

--


Gary


"deej" wrote in message
5.47...
"Gary Keramidas" <GKeramidasATmsn.com wrote in news:#AgjktfvHHA.4796
@TK2MSFTNGP04.phx.gbl:

try this, watch for wordwrap

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
Set ws = Worksheets("Past Results")
With ws
.Range("I2:L7").Sort Key1:=ws.Range("L3"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
.Range("I9:K40").Sort Key1:=ws.Range("K10"), Order1:=xlDescending,
Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
ws.Range("A2").Select
End Sub


Thankyou very much Gary, worked perfectly.

--
Posted via a free Usenet account from http://www.teranews.com



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie VBA Problem FCC[_4_] Excel Programming 5 July 2nd 06 05:47 PM
Newbie problem :( Liosan Excel Programming 6 August 15th 05 02:16 PM
Newbie Question: Data/Sort [email protected] New Users to Excel 1 February 21st 05 11:37 PM
Newbie Problem BuddyB Excel Programming 2 February 16th 05 04:45 AM
Newbie : Help with sort via Excel code Rich[_16_] Excel Programming 1 January 10th 04 12:20 AM


All times are GMT +1. The time now is 10:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"