Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Sort Problem - dynamically set the upper bound

I am sorting data and it is not sorting completely. I ploped the sort into my
code and forgot that my range is dynamic. The second range value is not the
same because the size of the output changes based on the data that I process
varies.

I know how many rows (by a variable) I have of output but how do I
dynamically set the Range.

The lower bound is A2 but the upper bound is not C20.

This is the sort I am using:

' Sort the report with preference in Ascending order
' 1) Logger ID, 2) Date and 3) Load Count
WBNew.Worksheets("Sheet1").Range("A2:C20").Sort _
Key1:=Worksheets("Sheet1").Range("B2"), _
Key2:=Worksheets("Sheet1").Range("A2"), _
Key3:=Worksheets("Sheet1").Range("C2")

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Sort Problem - dynamically set the upper bound

The solution is simple. Your sort range is defined by the following statement

WBNew.Worksheets("Sheet1").Range("A2:C20").Sort _

You just need to change the range to be variable

Lastrow = 125
WBNew.Worksheets("Sheet1").Range("A2:C" & LastRow).Sort _


"Nils Titley" wrote:

I am sorting data and it is not sorting completely. I ploped the sort into my
code and forgot that my range is dynamic. The second range value is not the
same because the size of the output changes based on the data that I process
varies.

I know how many rows (by a variable) I have of output but how do I
dynamically set the Range.

The lower bound is A2 but the upper bound is not C20.

This is the sort I am using:

' Sort the report with preference in Ascending order
' 1) Logger ID, 2) Date and 3) Load Count
WBNew.Worksheets("Sheet1").Range("A2:C20").Sort _
Key1:=Worksheets("Sheet1").Range("B2"), _
Key2:=Worksheets("Sheet1").Range("A2"), _
Key3:=Worksheets("Sheet1").Range("C2")

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Sort Problem - dynamically set the upper bound

Joel,

I was thinking that way but I did't use the right syntex.

Thanks

"Joel" wrote:

The solution is simple. Your sort range is defined by the following statement

WBNew.Worksheets("Sheet1").Range("A2:C20").Sort _

You just need to change the range to be variable

Lastrow = 125
WBNew.Worksheets("Sheet1").Range("A2:C" & LastRow).Sort _


"Nils Titley" wrote:

I am sorting data and it is not sorting completely. I ploped the sort into my
code and forgot that my range is dynamic. The second range value is not the
same because the size of the output changes based on the data that I process
varies.

I know how many rows (by a variable) I have of output but how do I
dynamically set the Range.

The lower bound is A2 but the upper bound is not C20.

This is the sort I am using:

' Sort the report with preference in Ascending order
' 1) Logger ID, 2) Date and 3) Load Count
WBNew.Worksheets("Sheet1").Range("A2:C20").Sort _
Key1:=Worksheets("Sheet1").Range("B2"), _
Key2:=Worksheets("Sheet1").Range("A2"), _
Key3:=Worksheets("Sheet1").Range("C2")

Thanks

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
"Sort" macro in late bound code Ian[_4_] Excel Programming 3 November 13th 07 10:18 PM
Bound Control On A Form Problem - Office 2003 Jeffrey_Chcgo Excel Programming 0 August 22nd 07 06:46 PM
Trying to group cells so that I can sort the upper most cell with. magnetoworld New Users to Excel 8 March 14th 05 07:17 PM
Upper & Lower case problem in VBA Rob Excel Discussion (Misc queries) 2 February 10th 05 07:46 AM
Dynamically set Sort keys Wilbur[_3_] Excel Programming 4 October 21st 03 09:21 PM


All times are GMT +1. The time now is 09:32 PM.

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

About Us

"It's about Microsoft Excel"