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

Hey, I had a problem that maybe someone can help me with.

I'm trying to sort a range in a macro. The columns that compose the
range never change, but the rows will. (i.e. columns a:o, but rows may
vary from 26:400 or 26:40)

I was trying to use range(selection, selection.end(xlDown)) and
range(selection, selection.end(xlToRight))

The selection.end(xlDown) works fine, but I have a partially blank
column in the middle of my column range. It has data for some jobs, but
not all. When I do selection.end(xlTo Right), it stops at this blank.
There is however, data I need sorted on the right of this column.

Is there a way to select the same columns every time, but check for the
end of data when adding rows to the selection?

I appreciate any help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Selecting and then sorting a range

Range("A1", "O" & Range("A1").End(xlDown).Row)

HTH
Die_Another_Day
Sharkbait wrote:
Hey, I had a problem that maybe someone can help me with.

I'm trying to sort a range in a macro. The columns that compose the
range never change, but the rows will. (i.e. columns a:o, but rows may
vary from 26:400 or 26:40)

I was trying to use range(selection, selection.end(xlDown)) and
range(selection, selection.end(xlToRight))

The selection.end(xlDown) works fine, but I have a partially blank
column in the middle of my column range. It has data for some jobs, but
not all. When I do selection.end(xlTo Right), it stops at this blank.
There is however, data I need sorted on the right of this column.

Is there a way to select the same columns every time, but check for the
end of data when adding rows to the selection?

I appreciate any help.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Selecting and then sorting a range

When trying to find the very last populated cell you are best to come up from
the bottom than to move down from the top as it will stop at the first blank.
This assumes that there is at least one column that is always populated. If
not then we need to get a bit more fancy than this...

dim rngToSort as range

set rngToSort = range(range("O1"), cells(rows.count, "A").end(xlup))

'rngtosort.sort ...
rngToSort.Select
--
HTH...

Jim Thomlinson


"Sharkbait" wrote:

Hey, I had a problem that maybe someone can help me with.

I'm trying to sort a range in a macro. The columns that compose the
range never change, but the rows will. (i.e. columns a:o, but rows may
vary from 26:400 or 26:40)

I was trying to use range(selection, selection.end(xlDown)) and
range(selection, selection.end(xlToRight))

The selection.end(xlDown) works fine, but I have a partially blank
column in the middle of my column range. It has data for some jobs, but
not all. When I do selection.end(xlTo Right), it stops at this blank.
There is however, data I need sorted on the right of this column.

Is there a way to select the same columns every time, but check for the
end of data when adding rows to the selection?

I appreciate any help.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Selecting and then sorting a range

You have other replies at your other posts.

Sharkbait wrote:

Hey, I had a problem that maybe someone can help me with.

I'm trying to sort a range in a macro. The columns that compose the
range never change, but the rows will. (i.e. columns a:o, but rows may
vary from 26:400 or 26:40)

I was trying to use range(selection, selection.end(xlDown)) and
range(selection, selection.end(xlToRight))

The selection.end(xlDown) works fine, but I have a partially blank
column in the middle of my column range. It has data for some jobs, but
not all. When I do selection.end(xlTo Right), it stops at this blank.
There is however, data I need sorted on the right of this column.

Is there a way to select the same columns every time, but check for the
end of data when adding rows to the selection?

I appreciate any help.


--

Dave Peterson
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
Sorting and Selecting dates kesslerjg Excel Discussion (Misc queries) 3 August 4th 09 07:27 PM
Selecting range in list of range names depending on a cell informa Courreges Excel Discussion (Misc queries) 2 June 19th 06 10:59 AM
Selecting a dynamic Range and sorting thiaga Excel Programming 3 March 1st 06 04:08 PM
Help please in selecting range dependent on another range MickJJ Excel Programming 2 January 10th 05 12:01 PM
Need help Selecting, Sorting, Autofitting a range Mr. Clean[_2_] Excel Programming 2 December 24th 03 07:48 PM


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