Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Sort selected range

How do I input the code to sort the selected range from here?

The range may be any row, so leave that portion open/variable.


Range("D65534").Select
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlToRight)).Select

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Sort selected range

Set rng = Range("D65534").End(xlUp)
Set rng = Range(rng, rng.End(xlToRight))
rng.Sort Key1:=rng.Cells(1, 1), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal


--
__________________________________
HTH

Bob

"J.W. Aldridge" wrote in message
...
How do I input the code to sort the selected range from here?

The range may be any row, so leave that portion open/variable.


Range("D65534").Select
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlToRight)).Select



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Sort selected range

getting error on this portion....

rng.Sort Key1:=rng.Cells(1, 1), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal


"application defined or object defined error"
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Sort selected range

That range Set will "break" if there are any blank cells in Column D's last
filled row anywhere to the right of Column D. This Set statement should work
for that condition as well as a range with no blank cells in the indicated
row)...

Set rng = Cells(Rows.Count, "D").End(xlUp).Resize(, Columns.Count - 3)

The 3 at the end is one less than the column's number value (Column "D" in
this case, which is column number 4, and one less than that is the 3 that I
used).

--
Rick (MVP - Excel)


"Bob Phillips" wrote in message
...
Set rng = Range("D65534").End(xlUp)
Set rng = Range(rng, rng.End(xlToRight))
rng.Sort Key1:=rng.Cells(1, 1), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal


--
__________________________________
HTH

Bob

"J.W. Aldridge" wrote in message
...
How do I input the code to sort the selected range from here?

The range may be any row, so leave that portion open/variable.


Range("D65534").Select
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlToRight)).Select




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Sort selected range

See if this is better

Set rng = Range("D65534").End(xlUp)
Set rng = Range(rng, rng.End(xlToRight))
rng.Sort Key1:=rng.Cells(1, 1), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal



--
__________________________________
HTH

Bob

"J.W. Aldridge" wrote in message
...
getting error on this portion....

rng.Sort Key1:=rng.Cells(1, 1), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal


"application defined or object defined error"



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 of range leaves range "selected" Mike Jamesson Excel Programming 3 July 25th 08 06:46 PM
Selected Sort hfazal Excel Programming 1 April 20th 06 06:08 PM
excel - sort, selected rows?? [email protected] Excel Worksheet Functions 2 December 24th 05 05:23 PM
when I auto sort in excel, How do I know how many are selected? tewmsesq Excel Worksheet Functions 1 September 22nd 05 09:10 AM
How to sort on the row selected by user? -JEFF-[_2_] Excel Programming 0 September 21st 05 07:36 PM


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