Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JBW JBW is offline
external usenet poster
 
Posts: 42
Default How to sort column data regardless of col length

HI,
I'm running a VBA macro and as part of it I need to sort a column of data,
the column length changes week on week. I have found by chance on one week
with 161 records that it only sorts 161 and leaves the other 4 alone and
they appear at the bottom of the column unsorted.

I did try changing the number to a large one ie 200 but it didnt like it at
all?


Sheets("Print Plan").Select
Columns("B:B").Select
Range("A1:J161").sort Key1:=Range("B1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default How to sort column data regardless of col length

Hi,

Assuming its the J161 bit that's going wrong and you really want to find the
bottom cell used in column J try this

lastrow = Range("J65536").End(xlUp).Row
Range("A1:J" & lastrow).sort Key1:=Range("B1"), Order1:=xlAscending,
Header:= _


Mike
"JBW" wrote:

HI,
I'm running a VBA macro and as part of it I need to sort a column of data,
the column length changes week on week. I have found by chance on one week
with 161 records that it only sorts 161 and leaves the other 4 alone and
they appear at the bottom of the column unsorted.

I did try changing the number to a large one ie 200 but it didnt like it at
all?


Sheets("Print Plan").Select
Columns("B:B").Select
Range("A1:J161").sort Key1:=Range("B1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JBW JBW is offline
external usenet poster
 
Posts: 42
Default How to sort column data regardless of col length

Thanks Mike, worked a treat

"Mike H" wrote:

Hi,

Assuming its the J161 bit that's going wrong and you really want to find the
bottom cell used in column J try this

lastrow = Range("J65536").End(xlUp).Row
Range("A1:J" & lastrow).sort Key1:=Range("B1"), Order1:=xlAscending,
Header:= _


Mike
"JBW" wrote:

HI,
I'm running a VBA macro and as part of it I need to sort a column of data,
the column length changes week on week. I have found by chance on one week
with 161 records that it only sorts 161 and leaves the other 4 alone and
they appear at the bottom of the column unsorted.

I did try changing the number to a large one ie 200 but it didnt like it at
all?


Sheets("Print Plan").Select
Columns("B:B").Select
Range("A1:J161").sort Key1:=Range("B1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

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
data, sort option is grayed. how to sort on a column? Steve Richter Excel Discussion (Misc queries) 1 September 25th 07 03:25 PM
Sort text list by character length - how? masterdiablo13 Excel Worksheet Functions 2 July 16th 06 07:45 PM
How do I sort a large column of data by length? blange Excel Worksheet Functions 3 May 29th 06 08:35 PM
How I type SOLD across column length without changing current data MommaRMe Charts and Charting in Excel 1 May 19th 05 09:11 AM
How do I sort a column of data and have each data row sort accordi Oedalis Excel Discussion (Misc queries) 1 March 17th 05 11:52 PM


All times are GMT +1. The time now is 02:17 AM.

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"