Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default error on sorting a range

Hi
I have an error happening when I run this Sort on a named range called
"DataRange" on the worksheet tab "Claim"

The message s
"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"

The code is

Application.Goto Reference:="DataRange"
ActiveWorkbook.Worksheets("Claim").Sort.SortFields .Clear
ActiveWorkbook.Worksheets("Claim").Sort.SortFields .Add
Key:=Range("DataRange"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Claim").Sort
.SetRange Range("DataRange")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

The Debug highlights the .Apply line.
When I step through the program the range is selected OK.
I recorded the code by selecting Goto button and selecting DataRange but
changed the cell reference from the B3:J60 notation to DataRange in the macro.


Correction suggestions please
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 913
Default error on sorting a range

On Sat, 14 Nov 2009 03:27:01 -0800, RocketRod
wrote:

Hi
I have an error happening when I run this Sort on a named range called
"DataRange" on the worksheet tab "Claim"

The message s
"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"

The code is

Application.Goto Reference:="DataRange"
ActiveWorkbook.Worksheets("Claim").Sort.SortFields .Clear
ActiveWorkbook.Worksheets("Claim").Sort.SortFields .Add
Key:=Range("DataRange"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Claim").Sort
.SetRange Range("DataRange")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

The Debug highlights the .Apply line.
When I step through the program the range is selected OK.
I recorded the code by selecting Goto button and selecting DataRange but
changed the cell reference from the B3:J60 notation to DataRange in the macro.


Correction suggestions please



Try changing
Key:=Range("DataRange")
to
Key:=Range("DataRange")(,n)
where n is the number of the column, within the range that you want
the range sorted by,

Key:=Range("DataRange")(,1)
if you want the data to be sort by the first column, column B in your
example.

Hope this helps / Lars-Åke
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default error on sorting a range

Thank you - that worked

"Lars-Ã…ke Aspelin" wrote:

On Sat, 14 Nov 2009 03:27:01 -0800, RocketRod
wrote:

Hi
I have an error happening when I run this Sort on a named range called
"DataRange" on the worksheet tab "Claim"

The message s
"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"

The code is

Application.Goto Reference:="DataRange"
ActiveWorkbook.Worksheets("Claim").Sort.SortFields .Clear
ActiveWorkbook.Worksheets("Claim").Sort.SortFields .Add
Key:=Range("DataRange"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Claim").Sort
.SetRange Range("DataRange")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

The Debug highlights the .Apply line.
When I step through the program the range is selected OK.
I recorded the code by selecting Goto button and selecting DataRange but
changed the cell reference from the B3:J60 notation to DataRange in the macro.


Correction suggestions please



Try changing
Key:=Range("DataRange")
to
Key:=Range("DataRange")(,n)
where n is the number of the column, within the range that you want
the range sorted by,

Key:=Range("DataRange")(,1)
if you want the data to be sort by the first column, column B in your
example.

Hope this helps / Lars-Ã…ke
.

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
VBA Sorting Error Scott Halper Excel Worksheet Functions 1 March 19th 08 01:27 PM
sorting error JT Excel Programming 2 September 16th 05 02:37 PM
sorting error ananga Excel Discussion (Misc queries) 2 June 30th 05 04:21 PM
error in sorting hans[_3_] Excel Programming 1 April 22nd 04 11:09 AM


All times are GMT +1. The time now is 01:25 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"