Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default range definition by cells numbers

I am trying to sort a few columns. This is the code I have. It does not work

it tells me that the sort reference is not valid

Sub Macro2()
Dim AKO As Range
Dim BKO as Range
Set AKO = Range(Sheet3.Cells(2, 13), Sheet3.Cells(362, 66)) 'Range("M2:M362")
Set BKO = Range(Sheet3.Cells(2, 13), Sheet3.Cells(362, 13)) 'Range("M2:M362")

ActiveWorkbook.Worksheets("RESULTS").Sort.SortFiel ds.Clear
ActiveWorkbook.Worksheets("RESULTS").Sort.SortFiel ds.Add Key:=AKO, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("RESULTS").Sort
.SetRange BKO
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,872
Default range definition by cells numbers

Hi,

Am Fri, 19 Oct 2012 13:35:45 -0700 (PDT) schrieb tuli:

Dim AKO As Range
Dim BKO as Range
Set AKO = Range(Sheet3.Cells(2, 13), Sheet3.Cells(362, 66)) 'Range("M2:M362")
Set BKO = Range(Sheet3.Cells(2, 13), Sheet3.Cells(362, 13)) 'Range("M2:M362")


try:
Set AKO = Sheets("Sheet3").Range(Cells(2, 13), Cells(362, 13))
or:
Set AKO = Sheets("Sheet3").Range("M2:M362")

change your code:

Dim AKO As Range
Dim BKO As Range

With Worksheets("RESULTS")
Set AKO = .Range(Cells(2, 13), Cells(362, 13))
Set BKO = Range(Cells(1, 1), Cells(362, 13))

.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=AKO _
, SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With .Sort
.SetRange BKO
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,872
Default range definition by cells numbers

Hi,

Am Fri, 19 Oct 2012 23:05:31 +0200 schrieb Claus Busch:

Set AKO = .Range(Cells(2, 13), Cells(362, 13))
Set BKO = Range(Cells(1, 1), Cells(362, 13))


look for the 2 rows above and change them to:

Set AKO = .Range(.Cells(2, 13), .Cells(362, 13))
Set BKO = .Range(.Cells(1, 1), .Cells(362, 13))


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default range definition by cells numbers

On Friday, October 19, 2012 4:35:46 PM UTC-4, tuli wrote:
I am trying to sort a few columns. This is the code I have. It does not work it tells me that the sort reference is not valid Sub Macro2() Dim AKO As Range Dim BKO as Range Set AKO = Range(Sheet3.Cells(2, 13), Sheet3.Cells(362, 66)) 'Range("M2:M362") Set BKO = Range(Sheet3.Cells(2, 13), Sheet3..Cells(362, 13)) 'Range("M2:M362") ActiveWorkbook.Worksheets("RESULTS").Sort.SortFiel ds.Clear ActiveWorkbook.Worksheets("RESULTS").Sort.SortFiel ds.Add Key:=AKO, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("RESULTS").Sort .SetRange BKO .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub


Thanks this worked
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
Range definition thewizz Excel Programming 2 October 29th 07 06:22 PM
Range Definition [email protected] Excel Programming 1 December 15th 06 11:28 AM
Using Address in Range Definition?? Don G Excel Programming 4 April 1st 06 01:18 AM
How come this range definition is invalid? keepITcool Excel Programming 1 June 21st 04 07:15 PM
Using Cells( ) for Range definition [email protected] Excel Programming 5 September 2nd 03 08:04 PM


All times are GMT +1. The time now is 07:59 PM.

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"